Home » Tag Archives: Enums

Tag Archives: Enums

Of Hacking Enums and Modifying ‘final static’ Fields


In this newsletter, originally published in The Java Specialists’ Newsletter Issue 161 we examine how it is possible to create enum instances in the Sun JDK, by using the reflection classes from the sun.reflect package. This will obviously only work for Sun’s JDK. If you need to do this on another JVM, you’re on your own. This all started with ...

Read More »

Java Enum puzzler


Let’s suppose we have the following code: enum Case { CASE_ONE, CASE_TWO, CASE_THREE; private static final int counter; private int valueDependsOnCounter; static { int sum = 0; for(int i = 0; i<10; i++) { sum +=i; } counter = sum; } Case() { this.valueDependsOnCounter = counter*counter; } } What do you think is the result of compiling and running the ...

Read More »
Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.