Wrapper class variable in switch

We can pass primitive values like int,char to switch statement. But this code passes an object of Integer (wrapper) variable to the switch statement. The compiler didn't complain anything about this. It executed perfectly.

boolean testIfFound(Integer i) { boolean found; final int switchValue = i.intValue(); switch(i) { case 0: found = true; case 1: found = true; // ..... and so on // ..... and so on // ..... and so on // ..... and so on // ..... and so on // ..... and so on }

Originally posted by Nicholas Jordan: boolean testIfFound(Integer i) { boolean found; final int switchValue = i.intValue(); switch(i) { case 0: found = true; case 1: found = true; // ..... and so on // ..... and so on // ..... and so on // ..... and so on // ..... and so on // ..... and so on }

Yes, I did - but the switch I wrote will cascade along the steppes and could have as well have been written:

Switch cases do not necessarily need the breaks, in this one the cascading down the chain just wastes a few dozen processor cycles ~ the effect is the same. [ September 21, 2007: Message edited by: Nicholas Jordan ]