Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Static Initializers best practice?

cowwoc-JavaNetOct 30 2008 — edited Oct 30 2008
Hi,

In Effective Java, Joshua Bloch recommends using static initializers instead of lazy initializers whenever possible. I see one major with that advice: exceptions.

As you can see from http://twasink.net/blog/archives/2006/07/how_not_to_hand.html there is a real lack of consensus when it comes to static initializers. In fact, I strongly suspect there is no good way to throw exceptions out of static blocks what-so-ever.

In that case, shouldn't they be avoided altogether? I'd love to hear your feedback.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 27 2008
Added on Oct 30 2008
20 comments
2,347 views