我正在尝试将新创建的对象添加到类的构造函数中的 ArrayList 中。新对象正在 main 方法的另一个类中创建。
主要方法:
public static void main(String[] args) {
// TODO code application logic here
Player p1 = new Player("Peter");
}
我的播放器类:
public class Player {
protected static int age;
protected static String name;
protected static ArrayList players = new ArrayList();
Player(String aName) {
name = aName;
age = 15;
players.add(new Player()); // i know this doesn't work but trying along these lines
}
}