<< July 26, 2004 | Home | July 28, 2004 >>

Java Generics Question

In my quest to develop a generic singleton class, I encountered this problem:

[weiqi@gao] $ cat Singleton.java
public class Singleton<T> {
  private static T instance;
  public static T getInstance() {
    if (instance == null) {
      instance = new T();
    }
    return instance;
  }
}
[weiqi@gao] $ javac Singleton.java
Singleton.java:2: non-static class T cannot be referenced from a static context
    private static T instance;
                   ^
Singleton.java:3: non-static class T cannot be referenced from a static context
    public static T getInstance() {
                  ^
Singleton.java:5: non-static class T cannot be referenced from a static context
            instance = new T();
                           ^
3 errors

Why? (Both C++ and C# allow similar constructs.)

IntelliJ IDEA 4.5: New Logo

Well, first things first. The first thing that catches my eyes with IntelliJ IDEA 4.5 is it's new logo:

IntelliJ IDEA 4.5 Released

Got the news from Jeff Brown:

IntelliJ IDEA 4.5 was released today.