Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about final

 
karnatam narendraprasad
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class test
{

public static void main ( String [] args )
{
final Integer x4 = 8;
final int x = 10;

switch ( x )
{
case x4:
System.out.println("4");
break;
case x:
System.out.println("x");
break;
}
}
}

the above code will not compile.
actiualy finl values cant be changed.but it give compile time error.why
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error message tells you "constant expression required." Constant expressions are defined under JLS 15.28 Constant Expression. Unboxed wrapper values are not included in this list.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic