samedi 28 février 2015

Missing return statement with switch


Vote count:

0





public AlertStatus nextStatus(){
int randNum = randNumGen.nextInt(3);
switch(randNum){
case 0: return new AlertStatusGreen();
case 1: return new AlertStatusYellow();
case 2: return new AlertStatusRed();
default: System.out.println("ERROR: no random number.");
}
}


This is a method in one of the classes for a program I have to make for school. The switch takes a random integer and uses it to return an object of a certain class that is derived from the class AlertStatus.


For some reason I keep getting an error saying "missing return statement }" for line 9 of the above block of code (the very last line in the above code). I don't understand why it's saying this though seeing as I already have return statements for each case.


Thanks!



asked 4 secs ago







Missing return statement with switch

Aucun commentaire:

Enregistrer un commentaire