我创建了一个超类(也可以用作基类):
public class CellView {
public CellViewHelper helper; // CellViewHelper is just an example
public CellView() {
this.helper = new CellViewHelper();
this.helper.someVariable = <anything>;
System.out.println("CellView_constructor");
}
public void draw() {
System.out.println("CellView_draw");
}
public void needsRedraw() {
this.draw();
}
}
public class ImageCellView extends CellView {
public Image someImage;
public ImageCellView() {
super();
this.someImage = new Image();
System.out.println("ImageCellView_constructor");
}
public void setSomeParam() {
this.needsRedraw(); // cannot be replaced by this.draw(); since it's some more complicated.
}
@Override public void draw() {
super.draw();
System.out.println("ImageCellView_draw");
}
}
现在,当我这样称呼它:
ImageCellView imageCellView = new ImageCellView();
imageCellView.setSomeParam();
我明白了:
CellView\u构造函数
但是,我希望它是:
ImageCellView\u构造函数
ImageCellView\u绘图
提前谢谢,
提姆
我还在CellView中实现了这个方法:
public void needsRedraw() {
this.draw();
}
以下是ImageCellView:
public void setSomeParam() {
this.needsRedraw(); // cannot be replaced by this.draw(); since it's some more complicated.
}
我一直在说:
ImageCellView ImageCellView=新建ImageCellView();
这是否会导致问题(当我从super调用函数时,它会调用super