0
我不明白爲什麼我的編譯器在參數有效時顯示非法參數異常。有任何想法嗎?拋出非法參數異常
public class bikeBrakeTest {
public enum BrakeType {Caliper, Cantilever, LinearPull, Disc };
public BrakeType brakes;
public bikeBrakeTest() //Defualt Constructor
{
brakes = BrakeType.Caliper;
}
public bikeBrakeTest(BrakeType aBrake) //Parameterized Constructor
{
setBrakes(aBrake);
}
public void setBrakes (BrakeType aBrake) //Mutator Method "set"
{
if (aBrake.equals("Caliper") || aBrake.equals("Cantilever") || aBrake.equals("LinearPull") || aBrake.equals("Disc"))
{
brakes = aBrake;
}
else throw new IllegalArgumentException("invalid");
}
}
然後我的測試車是..
public class testing {
public static void main(String[] args)
{
bikeBrakeTest myBike = new bikeBrakeTest();
myBike.setBrakes(bikeBrakeTest.BrakeType.Caliper);
}
}
1.它不是編譯器。 2.爲什麼你認爲'BrakeType'永遠等於'String'? –
「aBreak」不等於「Caliper」。不過,它可能等於'BrakeType.Caliper'。 –