我在尝试ArrayList
用 Java 创建一个时遇到了一个问题,但更具体地说是在尝试创建add()
它时。我在线收到语法错误people.add(joe);
...
Error: misplaced construct: VariableDeclaratorId expected after this token.
at people.add(joe);
^
我的理解是,ArrayList
就我的目的而言,an 比数组更好,所以我的问题是,是这样吗?如果不是,我的语法在哪里出错?
这是我的代码...
import java.util.ArrayList;
public class Person {
static String name;
static double age;
static double height;
static double weight;
Person(String name, double age, double height, double weight){
Person.name = name;
Person.age = age;
Person.height = height;
Person.weight = weight;
}
Person joe = new Person("Joe", 30, 70, 180);
ArrayList<Person> people = new ArrayList<Person>();
people.add(joe);
}