Java でを作成しようとしたときに問題が発生しましたArrayList
が、具体的にはそれを作成しようとしたときに発生しadd()
ました。行に構文エラーが表示されますpeople.add(joe);
...
Error: misplaced construct: VariableDeclaratorId expected after this token.
at people.add(joe);
^
私の目的では、配列よりも a の方が優れていると理解しているArrayList
ので、私の質問は、そうではない場合、構文のどこが間違っているのでしょうか?
これは私のコードです...
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);
}