Page 1 of 1
About Question enthuware.ocajp.i.v7.2.859 :
Posted: Tue Oct 16, 2012 10:48 am
by JQuirke
This won't compile for me, I know you can use a String object but not a String.
Can you please confirm this question is correct
http://docs.oracle.com/javase/tutorial/ ... witch.html
Re: About Question enthuware.ocajp.i.v7.2.859 :
Posted: Tue Oct 16, 2012 11:30 am
by admin
Hi,
I am not sure what you mean by "String object but not a String". The given code compiles and runs fine as explained in the explanation.
There is not much difference between switch("aaa") and switch(stringVariable). In case of switch("aaa"), a temporary reference (invisible to the programmer) is created and that is passed to the method, while in case of switch(stringVariable), stringVariable itself is the reference that is passed to the method.
HTH,
Paul.