以下代码:
import java.util.ArrayList;
import java.awt.Point;
public class Polygon{
ArrayList<Point> points;
//constructs polygon without points
public Polygon() {
points = new ArrayList<Point>();
}
/*
* adds a point to points
*/
public void addPoint(Point){
points.add(Point);
}
public void draw(){
for(int i = 0; i < points.size(); i++){
if(i == 0){
points.get(0).draw()
}else{
points.get(i).draw()
Line line = new Line(points.get(i-1).getX(), points.get(i-1).getY(), points.get(i).getX(), points.get(i).getY());
line.draw();
}
}
if(points.size() >= 2){
Line line = new Line(points.get(-1).getX(), points.get(-1).getY(), points.get(-2).getX(), points.get(-2).getY());
line.draw();
}
}
}
给出异常消息:
<identifier> expected for public void addPoint(Point)
我就是想不通为什么?通常需要这些标识符来告诉 ArrayList 它将保存哪些对象,对吗?