我正在研究一个类,它是一个后端类的视图,需要显示一些后端类属性。
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()
?