| Author |
Compile time constant
|
Vishnu Prakash
Ranch Hand
Joined: Nov 15, 2004
Posts: 1026
|
|
why am I getting error in main method when I try to assign a compile time constant to a byte variable(3). I am doing the same at (2) for byte b where I am not getting any error.
|
Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
I'll take a stab at this (meaning I could be wrong). If you look at the JLS, at the definition for a compile time constant, you will find:
# Simple names that refer to final variables whose initializers are constant expressions # Qualified names of the form TypeName . Identifier that refer to final variables whose initializers are constant expressions
nc.j is not one of these types of names. j is a simple name, and if j was static, FinalVarTest.j would be a correct qualified name. nc.j is accessing j through a reference to an object. It's a qualified name, but not of the form required by JLS. [ June 17, 2005: Message edited by: Barry Gaunt ]
|
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Here I made j static as well as final: That compiles.
|
 |
Barry Gaunt
Ranch Hand
Joined: Aug 03, 2002
Posts: 7729
|
|
Here I've used j (simple name) and this.j (a qualified name - but not of the type required by JLS)
|
 |
Vishnu Prakash
Ranch Hand
Joined: Nov 15, 2004
Posts: 1026
|
|
That was the doubt I had for a long time. Thanks for the wonderful explanation.
|
 |
 |
|
|
subject: Compile time constant
|
|
|