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

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -