I have encountered the following scenario and I cannot find a simple solution.
#1
public class Foo<T> {
@Override
public T bar() {
// access T.class
}
}
Java Generics always want the Generic type to be of type class. So it is natural to expect to access the class type. Why it doesn't work that way?
#2
public class Foo<T> {
@Override
public T bar(Class C) {
// automatically infer T to be of type `C`
}
}
Is this possible in some way?
Elegant workarounds are welcome.