File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final variable initialization

 
vijayk kumar
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does a final variable initialized in overloaded constructors differently.
Then what about the necessity of intializing a variable at the declartion?
 
ramesh kumar
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
we can only initialize final variables once.
 
Tanka Banerjee
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do it. final can't be reintialized
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what these guys are celebrating with their . But to answer the question in a useful way, there is no requirement to initialize a final variable at declaration. For an instance variable, the requirement is that it needs to be assigned before the constructor completes. If you want t assign a final variable in a constructor, you must not assign it at declaration, since a final variable may be assigned only once. vijayk, does that answer your question?
 
Dana Bothner-By
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm... Your first sentense no verb.

Anyway, don't forget to assign a value in *every* constructor:
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"rammy,"

Please see Henry's warning about your display name under this other post. Basically, we need a last name too. Thanks!

(So far, you've used in 100% of your posts. :roll: )
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jim covered final fields. Final locals need never be assigned, but must be "definitely assigned" before they are used.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic