Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt in final variable

 
Vaibhav Chauhan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


why there is error at line 1. why compiler doesn't treat a as compile time constant.??
 
Mani Venkata Kanth
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi...

identifier expected at declaration....
if the final variable is of int type thn thr is error...

post exact error to find the reason...
 
Praveen Babu
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What does this mean

final a;

There is no primitive type as final.

try,

final byte a;

instead.

Regards,
Praveen
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



In java compile time constant is declared and initilized at a single line.
Variable a in your code is not compile time constant because you are declaring Variable a at one line and then initilization it at next line hence it is not compile time constant.
Check the above for compile time constant.
 
Praveen Babu
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

See the below URL,

Final Variables - Definite Assignment

It says a final varaible cannot be on the left side of an assignment.

Regards,
Praveen
[ September 04, 2006: Message edited by: Praveen Babu ]
 
Vaibhav Chauhan
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for all of you....
i am sorry that i missed identifier type ...it is

final int a;

thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic