You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,bro:
I try to get the raw type from lambda expression like this:
public interface Callback<T> { void handler(List<T> result); }
Callback<String> callback = result -> { //do something }; Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Callback.class, callback.getClass());
but I get the error type such as 'net.jodah.typetools.TypeResolver$Unknown'
so,how can I do?
The text was updated successfully, but these errors were encountered:
One level Class won't be able to get the actual generic type at runtime in its class, cause when source code file(.java) compile to bytecode file(.class), will erase T to java.lang.Object(T:Ljava/lang/Object) rather than actual type you defined in other place of your code.
By the way, if subclasses write the actual type arguments(or bound type parameter) when extends generic type class, then such generic info will be saved in bytecode's class signature when you compile them. As a result, you can get the actual type from them.
See: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3
In conclusion, Callback<String> and Callback<Integer> are the same from the Callback class bytecode side(and runtime) view, so unless you tell it which type you are using(by invoking its method), reflection can only get the type as java.lang.Object from Callback itself.
@jhalterman This issue can close now.
But I think this method should return an Object.class(or throw an unsupported exception) rather than return an unknown object.
Hi,bro:
I try to get the raw type from lambda expression like this:
public interface Callback<T> { void handler(List<T> result); }
Callback<String> callback = result -> { //do something }; Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Callback.class, callback.getClass());
but I get the error type such as 'net.jodah.typetools.TypeResolver$Unknown'
so,how can I do?
The text was updated successfully, but these errors were encountered: