| Author |
final variables can be manipulated ...found this in SCWCD book by Bert!
|
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
|
|
Ok! This question is not specific to Servlets . However, I came across this while reading the SCWCD book by Bert....
It states that final variable in Java can be manipulated.....
Can you give me an example. I always thought that final means dead end. I mean that is it! It can not be changed as long as the scope of the varibale remains. When the scope dies, the GC might come in and destroy the variable. Now I know that it can be manipulated. I learn better with siimple small code.. PleasE?
|
Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can
|
 |
Ankur Jain Kothari
Ranch Hand
Joined: Feb 08, 2010
Posts: 152
|
|
|
what page did you find this?
|
Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)
|
 |
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
|
|
Ankur Jain Kothari wrote:what page did you find this?
page 202... of 1st edition!
|
 |
Ankur Jain Kothari
Ranch Hand
Joined: Feb 08, 2010
Posts: 152
|
|
|
then which topic?i have 2nd edition
|
 |
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
|
|
Ankur Jain Kothari wrote:then which topic?i have 2nd edition
in 2nd edition it is on page 204....
|
| Filename |
final are not final.jpg |
Download
|
| Description |
|
| Filesize |
34 Kbytes
|
| Downloaded: |
12 time(s) |
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9090
|
|
|
Can you quote the exact statement?? Maybe you interpreted it wrong...
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
|
|
Ankit Garg wrote:Can you quote the exact statement?? Maybe you interpreted it wrong...
I think I might have interpreted it wrong.. ANyhow, I just put up an image with the statement there.. Please check! Thanks :-)
|
 |
Harpreet Singh janda
Ranch Hand
Joined: Jan 14, 2010
Posts: 317
|
|
Final variable can be changed, if you are talking about the variables of any object type.
Means we can change the members of that final variable but we can not change the reference.
For example suppose we have below class:
and we have declared it final as:
Even this variable is final but still be can change the value of variable i like
but we can not change the reference like:
means we can not reassign the object.
Final means we can not change the value of the variable and in case of object variable this value is always a reference to an object on heap. So here we can not change the reference but still it is legal to change the underlying variable states.
|
 |
vinayak chobe
Greenhorn
Joined: Jul 15, 2008
Posts: 6
|
|
|
I think it means that If a final variable holds a reference to an object then state of the object may be changed but the variable will always refer to the same object
|
Vinayak Chobe
SCJP 1.4
|
 |
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
|
|
Harpreet Singh janda wrote:Final variable can be changed, if you are talking about the variables of any object type.
Means we can change the members of that final variable but we can not change the reference.
For example suppose we have below class:
and we have declared it final as:
Even this variable is final but still be can change the value of variable i like
but we can not change the reference like:
means we can not reassign the object.
Final means we can not change the value of the variable and in case of object variable this value is always a reference to an object on heap. So here we can not change the reference but still it is legal to change the underlying variable states.
Honestly! I never thought this deep! Wow! Thanks
|
 |
Harpreet Singh janda
Ranch Hand
Joined: Jan 14, 2010
Posts: 317
|
|
Yes, vinayak chobe you are right.
|
 |
Jayant Kaushal
Greenhorn
Joined: Nov 21, 2011
Posts: 6
|
|
Java is such an amazing language.
Anything is possible,You just have to find a way.
Nice post guys. Enjoyed reading.
Keep it up.
|
 |
 |
|
|
subject: final variables can be manipulated ...found this in SCWCD book by Bert!
|
|
|