This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a very stupid doubt in using enums in switch. I am really confused though.
This is a sample of code from K&B chapter 5
The output in this case is green. I read somewhere specification says that, if you have to use enum's as case
constant, you must specify them without fully qualified name. I am puzzled how compiler is interpreting red and
green and blue in this case as a case label.
From one perspective, the "red and green and blue" are interpreted by the compiler as legal enum constants because the variable c is of enum type Color. If you create another enum such as Direction and try it like so:
then the compiler will report that red and green and blue "cannot be resolved or is not a field" because the switch is now on Direction, not Color.