从Java开始,我希望创建时构造函数中的一个参数不超过某个值。举个例子 :
public class Vehicule {
protected String immat;
protected int poidsVide;
protected int charge;
protected int chargeMax;
Vehicule(String immat, int poidsVide, int charge) {
this.immat = immat;
this.poidsVide = poidsVide;
this.charge = charge;
this.chargeMax = 10000;
}
}
Run Code Online (Sandbox Code Playgroud)
我不希望任何带有“ charge”优于“ chargeMAx”实例的对象该怎么办?尝试了几种选择,到目前为止没有用。
谢谢你的帮助。