public class Switch {
public static void main(String[] args) {
final Integer i=new Integer(2);
switch(i)
{
case i:System.out.println("hi");
}
}
}
When I am compiling it then it is giving error saying that case must be a consatnt but if I write below code then no error.Why so?
public class Switch {
public static void main(String[] args) {
final int i=2;
switch(i)
{
case i:System.out.println("hi");
}
}
}