这两段代码的区别是什么,第二个有错应该怎么改?
private CircularQueue> bufferLogs = new CircularQueue >();
public void Write(Log log){
List logs = new ArrayList();
logs.add(log);
bufferLogs.ForceEnqueue(logs);
if(BaseAdapter!=null && bufferLogs.getCount()>=Size)
{
for(int i=bufferLogs.getCount();i>=0;i--)
{
logs.addAll(bufferLogs.Dequeue());
}
BaseAdapter.Write(logs);
}
}
--------------------------------------
public void Write(Log log){
bufferLogs.ForceEnqueue(logs);//此处有错 类型错误 而且logs在里面定义
if(BaseAdapter!=null && bufferLogs.getCount()>=Size)
{
List<Log> logs = new ArrayList<Log>();
for(int i=bufferLogs.getCount();i>=0;i--)
{
logs.addAll(bufferLogs.Dequeue());
}
BaseAdapter.Write(logs);
}
}
我写的第一种,老师说不行 要第二种 给了那样的代码 错误那里让我自己想办法改 我实在想不出啊 来个大神。
public void Write(Log log){
if(BaseAdapter!=null && bufferLogs.getCount()>=Size)
{
List logs = new ArrayList();
bufferLogs.ForceEnqueue(logs);//此处有错 类型错误 而且logs在里面定义
for(int i=bufferLogs.getCount();i>=0;i--)
{
logs.addAll(bufferLogs.Dequeue());
}
BaseAdapter.Write(logs);
}
}
这是修改的,你试试
public void Write(Log log){
bufferLogs.ForceEnqueue(logs);
if(BaseAdapter!=null && bufferLogs.getCount()>=Size)
{
List logs = new ArrayList(); 在这声明,实例化logs却在上面调用,显然错了bufferLogs.Force(logs)要在实例化之后
for(int i=bufferLogs.getCount();i>=0;i--)
{
logs.addAll(bufferLogs.Dequeue());
}
BaseAdapter.Write(logs);
}
}