There is a generic interface:
public interface IMyQueue<T> {
//...
}
and there is a generic class implementing it:
public class MyQueueImp<T> implements IMyQueue<T> {
//...
}
I want the implementation to have a factory method: a public static method getInstance
that instantiate an object for that generic class.
public class MyQueueImp<T> implements IMyQueue<T> {
public static IMyQueue getInstance() {
///....
}
}
So I can call it like this:
IMyQueue<Integer> queue = MyQueueImpl.getInstance();
The problem is within this static methods there is not access to generic T
:
MyPriorityQueueImpl.this' cannot be referenced from a static context
I'm wondering how should I do this?