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

Array Initialization Doubt

 
Srividhya Kiran
Ranch Hand
Posts: 166
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

why am I getting compilation error at line 2 and not in line1. At line 2 I am getting an error saying can't assign a value to a final variable.



Thanks
Srividhya
 
Edwin Keeton
Ranch Hand
Posts: 214
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static means that the member variable is created and initialized when the class is loaded by the Java interpreter. Final means that the value cannot be changed after it is initialized. The static initialization block in line 1 is called when the class is loaded. The class has already been loaded by the timeLine 2 attempts to initialize the array in a method, and therefore is illegal to attempt to change the value of the final variable.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic