Get your CodeRanch badge!*
The moose likes Beginning Java and the fly likes Final Arguments .. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Final Arguments .." Watch "Final Arguments .." New topic
Author

Final Arguments ..

karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
Can final arguments of a method can changed ??


karim
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
final arguments in any scope cannot be changed. They can be read from, any number of times.
karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
thanks Dawn
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Their content can be changed though.


[My Blog]
All roads lead to JavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
Please explain more about changing content, Christophe.
Muhammad Khojaye
Ranch Hand

Joined: Apr 12, 2009
Posts: 449

karimkhan pathan wrote:Can final arguments of a method can changed ??


Values cannot be modified after initialization. however, they are stored as values. Just to confuse things static final variables in Java are compiled as in-line constants. In other words, if you change a static final value, you need to recompile everything that uses it or they will continue using the old value. That catches out every Java newbie sooner or later.


http://muhammadkhojaye.blogspot.com/
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Please explain more about changing content, Christophe.

karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
But when a primitive is used as a argument for the method .
we cannot change the value !!
when we use a object ref how we can change the contents of the object?
Amy Crowley
Greenhorn

Joined: Apr 19, 2009
Posts: 6
Final variables cannot be reassigned new values once they've been initialized. For object reference variables, this means that the final variable cannot be re-assigned to a different object. The object itself may be changed, however -- the certification tutorial i've been reading (SCJP 6 Study Guide, Sierra & Bates) put it this way:
There are no final objects, only final references.


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
karimkhan pathan wrote:when we use a object ref how we can change the contents of the object?
That is what I expected, and why I sugested Christophe give us more details (thank you).

You cannot change which object it is, but the methods allow you to change the "state" of the object; its fields can be altered.
karimkhan pathan
Ranch Hand

Joined: Jul 14, 2008
Posts: 86
Thanks campbell...It was really helpful ...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36453
    
  15
You're welcome (on behalf of everybody who replied)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Final Arguments ..
 
Similar Threads
Generic Class
javaprogramming
why netbeans suggested to make my local reference variable final ?
Answer :Run time error / why?
Confused with var-args.