This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
final variables can be manipulated ...found this in SCWCD book by Bert!
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
posted
0
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: 154
posted
0
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
posted
0
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: 154
posted
0
then which topic?i have 2nd edition
Swagato Bhatta
Ranch Hand
Joined: Nov 08, 2008
Posts: 72
posted
0
Ankur Jain Kothari wrote:then which topic?i have 2nd edition
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
posted
0
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
posted
0
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.