File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes final reference variable doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

final reference variable doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

BOOK-->>K&B 6
Final Variables
Declaring a variable with the final keyword makes it impossible to reinitialize that variable once it has been initialized with an explicit value (notice we said explicit rather than default). For primitives, this means that once the variable is assigned a value, the value can't be altered. For example, if you assign 10 to the int variable x, then x is going to stay 10, forever. So that's straightforward for primitives, but what does it mean to have a final object reference variable? A reference variable marked final can't ever be reassigned to refer to a different object. The data within the object can be modified, but the reference variable cannot be changed. In other words, a final reference still allows you to modify the state of the object it refers to, but you can't modify the reference variable to make it refer to a different object. Burn this in: there are no final objects, only final references. We'll explain this in more detail in Chapter 3.


I want know that how data of that object can modify.

like final Integer i=new Integer(5);

how data of this object can be modify ?


Tell the difficulties that i am difficult.
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10202
    
166

Here's an example which might help you understand what that statement means:



[My Blog] [JavaRanch Journal]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4421
    
    8

This is a (probably accidental) duplicate of http://www.coderanch.com/t/586560/java/java/final-reference-variable. I'll lock this thread, so any further discussion can take place back there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final reference variable doubt