我很困惑,我认为我在做一些非常愚蠢的事情,我只是看不到它!
中央供暖控制:
一个Radiator类和一个RadiatorSize类。散热器有一个尺寸实例变量,它属于 RadiatorSize 类。我有 XSMALL,... XLARGE 的散热器尺寸;在 RadiatorSize 中定义为公共枚举。
所以,我在想,创建一个新的散热器并给它一个中等大小。
size = new RadiatorSize(RadiatorSize.Size.MEDIUM);
Netbeans 告诉我:
...\CentralHeating\src\hardwaremodel\Radiator.java:17:
error: constructor RadiatorSize in class RadiatorSize cannot be
applied to given types;
size = new RadiatorSize(RadiatorSize.Size.MEDIUM);
required: no arguments
found: Size
reason: actual and formal argument lists differ in length
1 error
这是违规的课程。
/** Radiator class **/
package hardwaremodel;
import units_constants.RadiatorSize;
public class Radiator {
private int boilerSequence;
private RadiatorSize size;
private double volume; //cubic centimetres
public void Radiator(int blrSqnc) {
boilerSequence = blrSqnc;
size = new RadiatorSize(RadiatorSize.Size.MEDIUM); //ERROR HERE
}
}
/** RadiatorSize class **/
package units_constants;
public class RadiatorSize {
public enum Size {XSMALL, SMALL, MEDIUM, LARGE, XLARGE};
private Size size;
public void RadiatorSize(Size sz) {
size = sz;
}
}
现在,Netbeans 给了我一个提示,它建议“在 units_constants.RadiatorSize 中创建构造函数 RadiatorSize(units_constants.RadiatorSize.Size)”;当我同意时它会这样做:
public RadiatorSize(Size size) {
throw new UnsupportedOperationException("Not yet implemented");
}
现在编辑器中已经没有小红圈了,但是……!
我很困惑。