Ihar Hancharenka 5dff80e88e first
2023-03-27 16:52:17 +03:00

26 строки
886 B
Plaintext

http://tutorials.jenkov.com/java-reflection/generics.html
https://github.com/jhalterman/typetools
https://github.com/FasterXML/java-classmate
http://fasterxml.github.io/java-classmate/javadoc/1.3/
2009
https://habr.com/ru/post/66593/
obtain generic type names
https://stackoverflow.com/questions/19906614/how-to-get-generic-return-type-of-a-method-using-reflections
https://stackoverflow.com/questions/3403909/get-generic-type-of-class-at-runtime
samples
Type returnType = method.getGenericReturnType();
System.out.println("method.getGenericReturnType(): " + returnType);
if (returnType instanceof ParameterizedType) {
ParameterizedType paramType = (ParameterizedType) returnType;
Type[] argTypes = paramType.getActualTypeArguments();
if (argTypes.length > 0) {
System.out.println("Generic type is " + argTypes[0]);
}
}