Generic Singleton in Java
<p>Why does the following code throws <em>java.lang.InstantiationException: generics.SingletonFoo$A</em>?</p>

<pre><code>public class SingletonFoo {
    private static Object _tn;

    public static &lt;T&gt; T instance(Class&lt;T&gt; t) {
        if (_tn != null) {
            return (T) _tn;
        }
        try {
            _tn = t.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return (T) _tn;
    }


    private class A{
        public A() {
        }
    }

    public static void main(String[] args) {
        System.out.println(SingletonFoo.instance(A.class));
    }
}
</code></pre>

<p>Is it related to type erasure somehow and it's not possible to create generic singleton in Java?</p>