Generics Revisited

In an earlier post about generics I described the limited impact of type erasure. Trying to describe that type erasure was more of a developer issue and less of a platform. Although I still agree with that statement, I want to show a case that adds some nuance to that statement. ...

April 8, 2012 · 2 min · Pal Hargitai

Generics in Java

There seem to be a significant amount of Java developers who have certain criticisms to the Java approach of implementing Generics. Though type information is sometimes well hidden, it's almost always available. This is because of the approach that Sun took when defining it. Sun decided that it was not appropriate to compile new types just because the type information itself changed. This approach differs from the C++ template approach which requires the original sources of the generic class you're using, this makes it very hard to provide a generic class in a library. ...

October 12, 2011 · 3 min · Pal Hargitai

Double Checked Locking Pattern

The Double-Checked Locking pattern used in the class loader testing example is used to lazily initialize the properties. Although there are some side notes with regard to the pattern. First and foremost, it only works for Java 1.5 and up, because of the Java memory model. Most developers shouldn't be worried with it. Quite frankly, the class loader testing example is not the most realistic example of an application for the pattern. Realistically, the best application for it is the lazy initialization of a true singleton instance, of which there are just very few. ...

September 18, 2011 · 2 min · Pal Hargitai

Testing with a Classloader

When building utility classes, testing becomes more important than in other parts of the software. Utilities are hopefully (re)used a lot and thus should have the most reliable behavior. This also means that documentation should always be up to date. Though utilities are generally easy, they might not be the easiest to test. I created a little example of a utility that I often use, depending on the application, often bearing the name "SettingsUtil". It's a simple class that returns properties from a property file somewhere on the classpath and returns either the value for a specified key from the properties file or a default value if no value is associated with the given key. ...

July 24, 2011 · 3 min · Pal Hargitai