Java Reflection – получить универсальный тип с возможным универсальным или универсальным типом?JAVA

Программисты JAVA общаются здесь
Гость
Java Reflection – получить универсальный тип с возможным универсальным или универсальным типом?

Сообщение Гость »


I need to determine the generic type(s) applied to a Java at runtime. For a situation like , that is rather easy. I have code that looks like this:

Код: Выделить всё

protected Class[] getGenericParameterTypes(Field field) {
ParameterizedType pt = (ParameterizedType) field.getGenericType();
Type[] types = pt.getActualTypeArguments();
Class[] ptClasses = new Class[types.length];

for (int i = 0; i < types.length; i++) {
ptClasses[i] = (Class) types[i];
}

return ptClasses;
}
This works fine for the simple use case. What I'm struggling with is a situation that popped up where I have a more complex , like or . How do I apply this logic to get the types/parameterized types for this ?


Источник: https://stackoverflow.com/questions/780 ... of-generic

Вернуться в «JAVA»