Mike Gualeni wrote:I have the following code:
Why the switch expression take case y? For me switch( x+y ) is 2, also it should print default. x and y are both final! And I thought (x+y) is allowed in a switch expression?
Thanks for help.
because the switch evaluates the x+y =2 then compiler search for a related value, case y: has the value 2, so it jumps to case y but not the default reason is that switch has the ability to create a jump statement whatever the cases you have, so answer is case y exicuited which has the value 2 related to case x+y