| Author |
doubt in finally variable
|
raja ram
Ranch Hand
Joined: Mar 02, 2008
Posts: 169
|
|
Hi, What is the meaning of statement "final variables can still be manipulated unless its immutable" i know that final variables do not take default values however they should and must be initalized before the completion of constructor. like public class test{ final int i; test(){ i=10' } } will work with out any problem but what is the meaning of above statement can any body give me example for this. Thanks
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12953
|
|
Your example works because the variable i has not yet been initialized at declaration. If you change it like this, it will not compile anymore: But I don't think that is what the original statement is about. This is what it means: You cannot change the value of a final variable after it has been initialized, but you can change the content of the object that the variable refers to (unless the object is immutable). For example: [ March 27, 2008: Message edited by: Jesper Young ]
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
raja ram
Ranch Hand
Joined: Mar 02, 2008
Posts: 169
|
|
Hi, Thanks for the reply. yes what you are saying is correct but my doubt was what the statement means i am aware of the concepts you are explaining but what actually this statement means can any body explain me. Thanks
|
 |
Gaurav Joshi
Greenhorn
Joined: Mar 08, 2008
Posts: 18
|
|
|
Any ways final variables whose value is not initialized during declaration are called blank final variable
|
 |
raja ram
Ranch Hand
Joined: Mar 02, 2008
Posts: 169
|
|
Hi, any updates on this Thanks
|
 |
Sandeep Bhandari
Ranch Hand
Joined: Apr 16, 2004
Posts: 201
|
|
|
Can share some more lines in front and after it from the source you got it.
|
SCJP 96% | SCWCD 90%| SCJP mock exams | My SCJP blog
|
 |
raja ram
Ranch Hand
Joined: Mar 02, 2008
Posts: 169
|
|
Hi, I found this line in the SCWCD book of HFSJ. there are no code example but this line when discussing about the context-param. Thanks
|
 |
Sandeep Bhandari
Ranch Hand
Joined: Apr 16, 2004
Posts: 201
|
|
I would rephrase the line as: Final references can still be manipulated unless underlying object is immutable
|
 |
 |
|
|
subject: doubt in finally variable
|
|
|