In Java (prior to 5.0), a lot of times you are compelled to downcast your object to a more specific one. For example, when you add a String to a List, and when you want to retrieve your String back then you need to downcast. List myList = new ArrayList(); myList.add(“abc”); String str = (String)myList.get(0); …
Monthly Archives: December 2006
Bootstrapping static fields within enums
In my earlier post on enums in Java 5, we have seen that static fields cannot be accessed within the enum constructor. With this restriction we could run into few initialization problems discussed below. The other day Rajiv found it difficult to initialize a static cache during enum bootstrap. The following is his enum: public …