So before I ask the question, I feel that I must explain my situation for the question to make any logical sense:
I have the generic nested class
ThreadHierarchy<P,C extends ExtendedThreadHandler<T>>
(where P represents the parent and C, the child) inside of the generic class ExtendedThreadHandler<T>
(where T represents type), and I need to create an instance of the TheradHierarechy
class in the main constructor of its superclass like so:
//Thread State initializer
public ExtendedThreadHandler() {
this.setThreadClass((T)this);
this.setThreadName(getClassInstance().getClass().getSimpleName());
ThreadHierarchy th = new ThreadHierarchy<Thread.currentThread().getClass(), T>(true);
}
The issue with this is that while instantiating classes, the generic input values only accept string literals such as the predefined generic type T
from ExtendedTheadHandler<T>
, and therefore, I cannot input a method call or variable into the instance parameters.
Is there a way to either:
A) Input return values, in this case a class, into a generic class or method by defining a new instance variable to pass in? (I couldn't figure out how to do this)
OR
B) Use reflection to create an instance of the class where the values of P
and C
can be assigned manually?
Aucun commentaire:
Enregistrer un commentaire