in C #, we can define a generic class A<T> where T : new() . In this code, we can create an instance of T with new T() . How is this implemented in Java? I read an article that says this is not possible.
The reason I used has a singleton patten using common code in C #, for example:
public static class Singleton<T> where T : new() { private static T instance; public static T Instance { get { if (instance == null) { instance = SingletonCreater.Instance; } return instance; } } static class SingletonCreater { internal static readonly T Instance = new T(); } }
And how to make this method more graceful?
source share