我收到以下错误:
array required, but java.lang.String found
Run Code Online (Sandbox Code Playgroud)
我不知道为什么。
我想做的是将一个对象的实例(我认为这是正确的术语)放入该类型的类(对象的)数组中。
我上课:
public class Player{
public Player(int i){
//somecodehere
}
}
Run Code Online (Sandbox Code Playgroud)
然后在我的main方法中创建它的一个实例:
static final Player[] a = new Player[5]; // this is where I'm trying to create the array.
public static void main(String[] args){
Player p = new Player(1);
a[0] = p; //this is the line that throws the error
}
Run Code Online (Sandbox Code Playgroud)
任何想法为什么会这样?