我在另一个类中声明了一个新的“世界”对象,如下所示:
fray.World world = new fray.World();
java 编译器提示它找不到构造函数(类在 fray
包中的位置没问题)。
我在 fray.World 类中有以下构造函数:
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];
}
发生什么事了?
最佳答案
您应该更改构造函数的可见性,以便可以在其他包中使用它们,它们当前具有包级别访问权限。您可以尝试将它们设为公开
。
关于Java - 构造函数明显缺失,运算符重载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13735037/