到目前为止,我正在尝试制作一个ArrayList
对象,这些对象具有与我想按ArrayList
顺序调用的相同方法。
到目前为止,代码是这样的
public class Shape extends Application {
public void do(GraphicsContext canvas, int size, Color color){
;
}
}
public class Triangle extends Shape {
@Override
public void do(GraphicsContext canvas, int size, Color color){
canvas.setFill(Color.WHITE);
double[] xs = {60,80.0,50.0};
double[] ys = {60,120.0,50.0};
canvas.fillPolygon(xs,ys,3);
}
}
自动启动的主类是这样的
public class Main {
public void drawForegroundContent(GraphicContext canvas){
ArrayList<Shape> shpes = new ArrayList<Shape>();
Triangle t = new Triangle();
shapes.add(t);
shapes.add(t);
for (Shape k : shapes){
k.do(canvas,CoreColor.BLACK, 80);
}
}
}
但是错误是<identifier> expected
k.do(canvas, CoreColor.BLACK, 80)
此外,它对Shape类的void do
上的标识符也有类似的抱怨。这段代码到底有什么问题?