public final class ClassReflection extends Object
Constructor and Description |
---|
ClassReflection() |
Modifier and Type | Method and Description |
---|---|
static Class |
forName(String name)
Returns the Class object associated with the class or interface with the supplied string name.
|
static Annotation |
getAnnotation(Class c,
Class<? extends Annotation> annotationType)
Returns an
Annotation object reflecting the annotation provided, or null if this class doesn't have such an
annotation. |
static Annotation[] |
getAnnotations(Class c)
Returns an array of
Annotation objects reflecting all annotations declared by the supplied class, and inherited
from its superclass. |
static Class |
getComponentType(Class c)
Returns the Class representing the component type of an array.
|
static Constructor |
getConstructor(Class c,
Class... parameterTypes)
Returns a
Constructor that represents the public constructor for the supplied class which takes the supplied
parameter types. |
static Constructor[] |
getConstructors(Class c)
Returns an array of
Constructor containing the public constructors of the class represented by the supplied Class. |
static Annotation |
getDeclaredAnnotation(Class c,
Class<? extends Annotation> annotationType)
Returns an
Annotation object reflecting the annotation provided, or null if this class doesn't have such an
annotation. |
static Annotation[] |
getDeclaredAnnotations(Class c)
Returns an array of
Annotation objects reflecting all annotations declared by the supplied class, or an empty
array if there are none. |
static Constructor |
getDeclaredConstructor(Class c,
Class... parameterTypes)
Returns a
Constructor that represents the constructor for the supplied class which takes the supplied parameter
types. |
static Field |
getDeclaredField(Class c,
String name)
Returns a
Field that represents the specified declared field for the supplied class. |
static Field[] |
getDeclaredFields(Class c)
Returns an array of
Field objects reflecting all the fields declared by the supplied class. |
static Method |
getDeclaredMethod(Class c,
String name,
Class... parameterTypes)
Returns a
Method that represents the method declared by the supplied class which takes the supplied parameter types. |
static Method[] |
getDeclaredMethods(Class c)
Returns an array of
Method containing the methods declared by the class represented by the supplied Class. |
static Object[] |
getEnumConstants(Class c)
Returns the elements of this enum class or null if this Class object does not represent an enum type.
|
static Field |
getField(Class c,
String name)
Returns a
Field that represents the specified public member field for the supplied class. |
static Field[] |
getFields(Class c)
Returns an array of
Field containing the public fields of the class represented by the supplied Class. |
static Class[] |
getInterfaces(Class c) |
static Method |
getMethod(Class c,
String name,
Class... parameterTypes)
Returns a
Method that represents the public member method for the supplied class which takes the supplied parameter
types. |
static Method[] |
getMethods(Class c)
Returns an array of
Method containing the public member methods of the class represented by the supplied Class. |
static String |
getSimpleName(Class c)
Returns the simple name of the underlying class as supplied in the source code.
|
static boolean |
isAbstract(Class c)
Determines if the supplied Class object represents an abstract type.
|
static boolean |
isAnnotation(Class c)
Determines if the supplied Class object represents an annotation type.
|
static boolean |
isAnnotationPresent(Class c,
Class<? extends Annotation> annotationType)
Returns true if the supplied class includes an annotation of the given type.
|
static boolean |
isArray(Class c)
Determines if the supplied Class object represents an array class.
|
static boolean |
isAssignableFrom(Class c1,
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 boolean |
isEnum(Class c)
Determines if the supplied Class object represents an enum type.
|
static boolean |
isInstance(Class c,
Object obj)
Determines if the supplied Object is assignment-compatible with the object represented by supplied Class.
|
static boolean |
isInterface(Class c)
Determines if the supplied Class object represents an interface type.
|
static boolean |
isMemberClass(Class c)
Returns true if the class or interface represented by the supplied Class is a member class.
|
static boolean |
isPrimitive(Class c)
Determines if the supplied Class object represents a primitive type.
|
static boolean |
isStaticClass(Class c)
Returns true if the class or interface represented by the supplied Class is a static class.
|
static <T> T |
newInstance(Class<T> c)
Creates a new instance of the class represented by the supplied Class.
|
public static Class forName(String name) throws ReflectionException
ReflectionException
public static String getSimpleName(Class c)
public static boolean isInstance(Class c, Object obj)
public static boolean isAssignableFrom(Class c1, Class c2)
public static boolean isMemberClass(Class c)
public static boolean isStaticClass(Class c)
public static boolean isArray(Class c)
public static boolean isPrimitive(Class c)
public static boolean isEnum(Class c)
public static boolean isAnnotation(Class c)
public static boolean isInterface(Class c)
public static boolean isAbstract(Class c)
public static <T> T newInstance(Class<T> c) throws ReflectionException
ReflectionException
public static Class getComponentType(Class c)
public static Constructor[] getConstructors(Class c)
Constructor
containing the public constructors of the class represented by the supplied Class.public static Constructor getConstructor(Class c, Class... parameterTypes) throws ReflectionException
Constructor
that represents the public constructor for the supplied class which takes the supplied
parameter types.ReflectionException
public static Constructor getDeclaredConstructor(Class c, Class... parameterTypes) throws ReflectionException
Constructor
that represents the constructor for the supplied class which takes the supplied parameter
types.ReflectionException
public static Object[] getEnumConstants(Class c)
public static Method[] getMethods(Class c)
Method
containing the public member methods of the class represented by the supplied Class.public static Method getMethod(Class c, String name, Class... parameterTypes) throws ReflectionException
Method
that represents the public member method for the supplied class which takes the supplied parameter
types.ReflectionException
public static Method[] getDeclaredMethods(Class c)
Method
containing the methods declared by the class represented by the supplied Class.public static Method getDeclaredMethod(Class c, String name, Class... parameterTypes) throws ReflectionException
Method
that represents the method declared by the supplied class which takes the supplied parameter types.ReflectionException
public static Field[] getFields(Class c)
Field
containing the public fields of the class represented by the supplied Class.public static Field getField(Class c, String name) throws ReflectionException
Field
that represents the specified public member field for the supplied class.ReflectionException
public static Field[] getDeclaredFields(Class c)
Field
objects reflecting all the fields declared by the supplied class.public static Field getDeclaredField(Class c, String name) throws ReflectionException
Field
that represents the specified declared field for the supplied class.ReflectionException
public static boolean isAnnotationPresent(Class c, Class<? extends Annotation> annotationType)
public static Annotation[] getAnnotations(Class c)
Annotation
objects reflecting all annotations declared by the supplied class, and inherited
from its superclass. Returns an empty array if there are none.public static Annotation getAnnotation(Class c, Class<? extends Annotation> annotationType)
Annotation
object 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.public static Annotation[] getDeclaredAnnotations(Class c)
Annotation
objects reflecting all annotations declared by the supplied class, or an empty
array if there are none. Does not include inherited annotations.public static Annotation getDeclaredAnnotation(Class c, Class<? extends Annotation> annotationType)
Annotation
object 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.Copyright © 2018. All rights reserved.