java - Why cant we have wrapper class objects as constant? -
in java 7, given code:
final integer i=9; final int x=5; switch(x){ case 1: case i://compilation error thrown here }
what reason behind this?
integer = 9;
with i
reference integer object , it's not valid type switch on in java.
following valid variable types, can switch on
- convertible ints - int, byte,short,char
- enums
- string constants - support added in java 7
other these valid values, cannot switch on other object
Comments
Post a Comment