Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with initializing final static class member

 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a requirement where I need to initialize a final static member variable of a class, but the method which is used to initialize it, throws an exception. The code below may help to understand the issue:


How should I code so that I am able to initialize the final static variable?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15281
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could do something like this:

Does this have anything to do with SCJP?
I'm moving it to a more appropriate forum.
 
Darius Cooper
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your variable is final, yet you are not initializing it at the point of declaration, but rather trying to set it to some value later (i.e. in a "static" code block).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic