Page 1 of 1

About Question enthuware.ocajp.i.v7.2.860 :

Posted: Wed Nov 28, 2012 6:34 pm
by ETS User
public void switchString(String input){
switch(input){
case "a" : System.out.println( "apple" );
case "b" : System.out.println( "bat" );
break;
case "B" : System.out.println( "big bat" );
default : System.out.println( "none" );
}
}

public static void main(String[] args) throws Exception {
TestClasstc = new TestClass();
tc.switchString("B");
}

hi according to eclipse switch cannot evaluate string so this won't compile....

Re: About Question enthuware.ocajp.i.v7.2.860 :

Posted: Wed Nov 28, 2012 7:42 pm
by admin
Please try using JDK 1.7.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.860 :

Posted: Thu Dec 10, 2020 11:20 am
by jeff_kola
I thought the switch variable needs to be a compile time constant, and not passed through as parameters to functions according to Selikoff and Boyarsky book.

Re: About Question enthuware.ocajp.i.v7.2.860 :

Posted: Thu Dec 10, 2020 6:51 pm
by admin
No, switch case labels must be constants, not the switch variable.