类Java构造函数明显缺失,运算符重载
我在另一个类中声明了一个新的“world”对象,如下所示:
fray.World world = new fray.World();
java编译器抱怨找不到构造函数(类在fray
包中的位置没问题)
我有以下几位施工人员。世界级:
World() {
this(100, 100, 100);
}
World(int width) {
this(width, 100, 100);
}
World(int width, int length) {
this(width, length, 100);
}
World(int width, int length, int height) {
this.x = new int[width];
this.y = new int[length];
this.z = new int[height];
this.entities = new Entity[0];
}
怎么回事
# 1 楼答案
除非
World
是static inner class
,否则需要使用:# 2 楼答案
您应该更改构造函数的可见性,以便可以在其他包中使用它们,因为它们当前具有包级别的访问权限。你可以试着把它们做成
public