scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP2. Please Indent your code using UBB Code
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
SCJP2. Please Indent your code using UBB Code
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
A variable can be declared final. A final variable may only be assigned to once. It is a compile time error if a final variable is assigned to unless it is definitely unassigned (�16) immediately prior to the assignment.
A blank final is a final variable whose declaration lacks an initializer.
Once a final variable has been assigned, it always contains the same value.
SCJP2. Please Indent your code using UBB Code
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Barry, I think you're 100% right except for
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
private final int j=(int)Math.cos(0)*10;
is definitely not a compile-time constant, but
private final int j=10;
Ron, on the assumption that the variables are allocated and given the default values 0, and then the initializers run, and then the initialization blocks and finally the constructors all the results are predictable.
SCJP2. Please Indent your code using UBB Code
Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Originally posted by Barry Gaunt:
In the case of the member variable definition final int j = 10; doesn't compiler say "oh this is a constant, so I just replace j by 10 wherever it appears"? So instead of the variable getting the default value 0 in the first "memory allocate pass" it gets the constant (final) value of 10. Sort of...?
-Barry
SCJP, SCWCD
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
SCJP2. Please Indent your code using UBB Code
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |