File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt on instance initializer and constructor.

 
Ritesh raushan
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hava a some doubt.

1-why interface need a final variable.(what's the use of variable in interface)

2-what is the use of instance initializer even constructor is already for intialization
 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It used to be thought it was useful to put constants in interfaces so they would be available to implementing classes. More modern opinions: try here.
About initialisers: I don’t like them; they are called regardless of which constructor is invoked, so that might be a use.
 
Paul Clapham
Sheriff
Pie
Posts: 20203
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:About initialisers: I don’t like them; they are called regardless of which constructor is invoked, so that might be a use.


And if you have a situation (like in an anonymous inner class) where constructors cannot be used, then instance initializers are essential. (However, even though I use anonymous inner classes extensively, I don't believe I have ever found it necessary to put an instance initializer in one.)
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic