我正在研究一个类,它是后端类视图,需要显示一些后端类属性。在ArrayList中保留项目
public abstract class AGenericNodeView{
private ANode fObject;
private ArrayList<TInputView> fInputs = null;
public AGenericNodeView(){
super();
this.fInputs = new ArrayList<TInputView>();
}
private void getInputs(){
int num = fObject.getNumInputs(); //Number of inputs
for (int i = 0; i < num; i++)
{
this.fInputs.add(new TInputView());
this.fInputs.get(i).doSth();
}
//fInputs has now the size num which is greater than 0.
}
//later I call:
public draw()
{
//...
log(this.fInputs.size()); //output fInputs.size()
// and it is 0. Always.
}
}
我想,如果有一种方法,让我创建的对象在getInputs()
执着,所以该列表不是空的,需要draw()
什么时候?
在您使用它的地方添加相关的代码。 – BobTheBuilder 2013-03-14 13:40:08
您确定要调用getInputs()吗?你在同一个实例上调用getInputs()和draw()?因为它应该是“持久的”。 – 2013-03-14 13:40:10
“*,它是0. Always。*”=>看起来'draw'在'getInputs'之前被调用,那么......只有其他的可能性是如果你有两个不同的线程执行'draw'和'getInputs'。 – assylias 2013-03-14 13:40:21