我有一个(相当静态的)类,例如:
class Test
{
private Planet gault;
private Planet irtok;
private Planet ktaris;
/* problem:
private Planet [] planets = {
this.gault, this.irtok, this.ktaris
};
*/
Test() {
}
public void doTest() {
this.gault = new Planet("Klingon", 1322);
this.irtok = new Planet("Ferengi", 1213);
this.ktaris = new Planet("Ktarian", 16512);
}
}
我想要的(如果可以的话)是有一个指向每个行星的数组 - .
private Planet [] planets = {
this.gault, this.irtok, this.ktaris
};
这样我就doTest()
可以执行以下操作:
for (Planet p: in planets)
p.printInfo();
从我尝试过的各种方式来看,我总是以p
NULL 告终;