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

  1. convertible ints - int, byte,short,char
  2. enums
  3. string constants - support added in java 7

other these valid values, cannot switch on other object


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -