我想在 java 中创建一个通用的单例类,女巫给出了我传入方法参数的类的单例对象。类似下面的代码:请帮助
public final class Listener<T extends Object> {
private Listener() {
}
public static <T> Listener<?> getInstance(Class<T> clazz) {
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder {
public static final Listener INSTANCE = new Listener();
// private static final Map<Class<? extends Runnable>,Listener<? extends
// Runnable> INSTANCE = new ...;
}
}