Package com.badlogic.gdx.utils.reflect
Class ClassReflection
- java.lang.Object
-
- com.badlogic.gdx.utils.reflect.ClassReflection
-
public final class ClassReflection extends java.lang.ObjectUtilities for Class reflection.
-
-
Constructor Summary
Constructors Constructor Description ClassReflection()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ClassforName(java.lang.String name)Returns the Class object associated with the class or interface with the supplied string name.static AnnotationgetAnnotation(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns anAnnotationobject reflecting the annotation provided, or null if this class doesn't have such an annotation.static Annotation[]getAnnotations(java.lang.Class c)Returns an array ofAnnotationobjects reflecting all annotations declared by the supplied class, and inherited from its superclass.static java.lang.ClassgetComponentType(java.lang.Class c)Returns the Class representing the component type of an array.static ConstructorgetConstructor(java.lang.Class c, java.lang.Class... parameterTypes)Returns aConstructorthat represents the public constructor for the supplied class which takes the supplied parameter types.static Constructor[]getConstructors(java.lang.Class c)Returns an array ofConstructorcontaining the public constructors of the class represented by the supplied Class.static AnnotationgetDeclaredAnnotation(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns anAnnotationobject reflecting the annotation provided, or null if this class doesn't have such an annotation.static Annotation[]getDeclaredAnnotations(java.lang.Class c)Returns an array ofAnnotationobjects reflecting all annotations declared by the supplied class, or an empty array if there are none.static ConstructorgetDeclaredConstructor(java.lang.Class c, java.lang.Class... parameterTypes)Returns aConstructorthat represents the constructor for the supplied class which takes the supplied parameter types.static FieldgetDeclaredField(java.lang.Class c, java.lang.String name)Returns aFieldthat represents the specified declared field for the supplied class.static Field[]getDeclaredFields(java.lang.Class c)Returns an array ofFieldobjects reflecting all the fields declared by the supplied class.static MethodgetDeclaredMethod(java.lang.Class c, java.lang.String name, java.lang.Class... parameterTypes)Returns aMethodthat represents the method declared by the supplied class which takes the supplied parameter types.static Method[]getDeclaredMethods(java.lang.Class c)Returns an array ofMethodcontaining the methods declared by the class represented by the supplied Class.static java.lang.Object[]getEnumConstants(java.lang.Class c)Returns the elements of this enum class or null if this Class object does not represent an enum type.static FieldgetField(java.lang.Class c, java.lang.String name)Returns aFieldthat represents the specified public member field for the supplied class.static Field[]getFields(java.lang.Class c)Returns an array ofFieldcontaining the public fields of the class represented by the supplied Class.static java.lang.Class[]getInterfaces(java.lang.Class c)static MethodgetMethod(java.lang.Class c, java.lang.String name, java.lang.Class... parameterTypes)Returns aMethodthat represents the public member method for the supplied class which takes the supplied parameter types.static Method[]getMethods(java.lang.Class c)Returns an array ofMethodcontaining the public member methods of the class represented by the supplied Class.static java.lang.StringgetSimpleName(java.lang.Class c)Returns the simple name of the underlying class as supplied in the source code.static booleanisAbstract(java.lang.Class c)Determines if the supplied Class object represents an abstract type.static booleanisAnnotation(java.lang.Class c)Determines if the supplied Class object represents an annotation type.static booleanisAnnotationPresent(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns true if the supplied class includes an annotation of the given type.static booleanisArray(java.lang.Class c)Determines if the supplied Class object represents an array class.static booleanisAssignableFrom(java.lang.Class c1, java.lang.Class c2)Determines if the class or interface represented by first Class parameter is either the same as, or is a superclass or superinterface of, the class or interface represented by the second Class parameter.static booleanisEnum(java.lang.Class c)Determines if the supplied Class object represents an enum type.static booleanisInstance(java.lang.Class c, java.lang.Object obj)Determines if the supplied Object is assignment-compatible with the object represented by supplied Class.static booleanisInterface(java.lang.Class c)Determines if the supplied Class object represents an interface type.static booleanisMemberClass(java.lang.Class c)Returns true if the class or interface represented by the supplied Class is a member class.static booleanisPrimitive(java.lang.Class c)Determines if the supplied Class object represents a primitive type.static booleanisStaticClass(java.lang.Class c)Returns true if the class or interface represented by the supplied Class is a static class.static <T> TnewInstance(java.lang.Class<T> c)Creates a new instance of the class represented by the supplied Class.
-
-
-
Method Detail
-
forName
public static java.lang.Class forName(java.lang.String name) throws ReflectionExceptionReturns the Class object associated with the class or interface with the supplied string name.- Throws:
ReflectionException
-
getSimpleName
public static java.lang.String getSimpleName(java.lang.Class c)
Returns the simple name of the underlying class as supplied in the source code.
-
isInstance
public static boolean isInstance(java.lang.Class c, java.lang.Object obj)Determines if the supplied Object is assignment-compatible with the object represented by supplied Class.
-
isAssignableFrom
public static boolean isAssignableFrom(java.lang.Class c1, java.lang.Class c2)Determines if the class or interface represented by first Class parameter is either the same as, or is a superclass or superinterface of, the class or interface represented by the second Class parameter.
-
isMemberClass
public static boolean isMemberClass(java.lang.Class c)
Returns true if the class or interface represented by the supplied Class is a member class.
-
isStaticClass
public static boolean isStaticClass(java.lang.Class c)
Returns true if the class or interface represented by the supplied Class is a static class.
-
isArray
public static boolean isArray(java.lang.Class c)
Determines if the supplied Class object represents an array class.
-
isPrimitive
public static boolean isPrimitive(java.lang.Class c)
Determines if the supplied Class object represents a primitive type.
-
isEnum
public static boolean isEnum(java.lang.Class c)
Determines if the supplied Class object represents an enum type.
-
isAnnotation
public static boolean isAnnotation(java.lang.Class c)
Determines if the supplied Class object represents an annotation type.
-
isInterface
public static boolean isInterface(java.lang.Class c)
Determines if the supplied Class object represents an interface type.
-
isAbstract
public static boolean isAbstract(java.lang.Class c)
Determines if the supplied Class object represents an abstract type.
-
newInstance
public static <T> T newInstance(java.lang.Class<T> c) throws ReflectionExceptionCreates a new instance of the class represented by the supplied Class.- Throws:
ReflectionException
-
getComponentType
public static java.lang.Class getComponentType(java.lang.Class c)
Returns the Class representing the component type of an array. If this class does not represent an array class this method returns null.
-
getConstructors
public static Constructor[] getConstructors(java.lang.Class c)
Returns an array ofConstructorcontaining the public constructors of the class represented by the supplied Class.
-
getConstructor
public static Constructor getConstructor(java.lang.Class c, java.lang.Class... parameterTypes) throws ReflectionException
Returns aConstructorthat represents the public constructor for the supplied class which takes the supplied parameter types.- Throws:
ReflectionException
-
getDeclaredConstructor
public static Constructor getDeclaredConstructor(java.lang.Class c, java.lang.Class... parameterTypes) throws ReflectionException
Returns aConstructorthat represents the constructor for the supplied class which takes the supplied parameter types.- Throws:
ReflectionException
-
getEnumConstants
public static java.lang.Object[] getEnumConstants(java.lang.Class c)
Returns the elements of this enum class or null if this Class object does not represent an enum type.
-
getMethods
public static Method[] getMethods(java.lang.Class c)
Returns an array ofMethodcontaining the public member methods of the class represented by the supplied Class.
-
getMethod
public static Method getMethod(java.lang.Class c, java.lang.String name, java.lang.Class... parameterTypes) throws ReflectionException
Returns aMethodthat represents the public member method for the supplied class which takes the supplied parameter types.- Throws:
ReflectionException
-
getDeclaredMethods
public static Method[] getDeclaredMethods(java.lang.Class c)
Returns an array ofMethodcontaining the methods declared by the class represented by the supplied Class.
-
getDeclaredMethod
public static Method getDeclaredMethod(java.lang.Class c, java.lang.String name, java.lang.Class... parameterTypes) throws ReflectionException
Returns aMethodthat represents the method declared by the supplied class which takes the supplied parameter types.- Throws:
ReflectionException
-
getFields
public static Field[] getFields(java.lang.Class c)
Returns an array ofFieldcontaining the public fields of the class represented by the supplied Class.
-
getField
public static Field getField(java.lang.Class c, java.lang.String name) throws ReflectionException
Returns aFieldthat represents the specified public member field for the supplied class.- Throws:
ReflectionException
-
getDeclaredFields
public static Field[] getDeclaredFields(java.lang.Class c)
Returns an array ofFieldobjects reflecting all the fields declared by the supplied class.
-
getDeclaredField
public static Field getDeclaredField(java.lang.Class c, java.lang.String name) throws ReflectionException
Returns aFieldthat represents the specified declared field for the supplied class.- Throws:
ReflectionException
-
isAnnotationPresent
public static boolean isAnnotationPresent(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)Returns true if the supplied class includes an annotation of the given type.
-
getAnnotations
public static Annotation[] getAnnotations(java.lang.Class c)
Returns an array ofAnnotationobjects reflecting all annotations declared by the supplied class, and inherited from its superclass. Returns an empty array if there are none.
-
getAnnotation
public static Annotation getAnnotation(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns anAnnotationobject reflecting the annotation provided, or null if this class doesn't have such an annotation. This is a convenience function if the caller knows already which annotation type he's looking for.
-
getDeclaredAnnotations
public static Annotation[] getDeclaredAnnotations(java.lang.Class c)
Returns an array ofAnnotationobjects reflecting all annotations declared by the supplied class, or an empty array if there are none. Does not include inherited annotations.
-
getDeclaredAnnotation
public static Annotation getDeclaredAnnotation(java.lang.Class c, java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
Returns anAnnotationobject reflecting the annotation provided, or null if this class doesn't have such an annotation. This is a convenience function if the caller knows already which annotation type he's looking for.
-
getInterfaces
public static java.lang.Class[] getInterfaces(java.lang.Class c)
-
-