aspose file tools*
The moose likes Beginning Java and the fly likes Problem with initializing final static class member Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with initializing final static class member" Watch "Problem with initializing final static class member" New topic
Author

Problem with initializing final static class member

Satya Maheshwari
Ranch Hand

Joined: Jan 01, 2007
Posts: 368
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?


Thanks and Regards
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14104
    
  16

You could do something like this:

Does this have anything to do with SCJP?
I'm moving it to a more appropriate forum.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Darius Cooper
Greenhorn

Joined: Jul 10, 2008
Posts: 8
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with initializing final static class member