X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=gdx%2Fsrc%2Fcom%2Fbadlogic%2Fgdx%2Futils%2Freflect%2FField.java;h=769dc6c6305955598381e8462be6800f4a7f65fb;hb=841f50b233da7da97f67e24893093d3e10400b87;hp=91753fe36da320f8c23ec23100c59ad6f951779f;hpb=a52946ea593b02c2c54d3ee78467c59cbc50d1d7;p=mikumikustudio%2Flibgdx-mikumikustudio.git diff --git a/gdx/src/com/badlogic/gdx/utils/reflect/Field.java b/gdx/src/com/badlogic/gdx/utils/reflect/Field.java index 91753fe36..769dc6c63 100644 --- a/gdx/src/com/badlogic/gdx/utils/reflect/Field.java +++ b/gdx/src/com/badlogic/gdx/utils/reflect/Field.java @@ -1,6 +1,7 @@ package com.badlogic.gdx.utils.reflect; +import java.lang.reflect.GenericArrayType; import java.lang.reflect.Modifier; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -83,16 +84,22 @@ public final class Field { return field.isSynthetic(); } - /** If the type of the field is parameterized, returns the Class object representing the parameter type, null otherwise. */ - public Class getElementType () { + /** If the type of the field is parameterized, returns the Class object representing the parameter type at the specified index, + * null otherwise. */ + public Class getElementType (int index) { Type genericType = field.getGenericType(); if (genericType instanceof ParameterizedType) { Type[] actualTypes = ((ParameterizedType)genericType).getActualTypeArguments(); - if (actualTypes.length == 1) { - Type actualType = actualTypes[0]; + if (actualTypes.length - 1 >= index) { + Type actualType = actualTypes[index]; if (actualType instanceof Class) return (Class)actualType; - else if (actualType instanceof ParameterizedType) return (Class)((ParameterizedType)actualType).getRawType(); + else if (actualType instanceof ParameterizedType) + return (Class)((ParameterizedType)actualType).getRawType(); + else if (actualType instanceof GenericArrayType) { + Type componentType = ((GenericArrayType)actualType).getGenericComponentType(); + if (componentType instanceof Class) return ArrayReflection.newInstance((Class)componentType, 0).getClass(); + } } } return null;