public final class Class extends Object
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object other)
Returns if this object is considered equal to the other object.
|
static Class |
forName(String className)
This attempts to load a Class given the class name.
|
static Class |
forName(String className,
boolean initialize,
ClassLoader loader)
Load a Class using a specified ClassLoader.
|
ClassLoader |
getClassLoader()
Under Eve this will either return a valid ClassLoader or null if the class
was loaded by the normal bootstrap (VM) loader.
|
Class |
getComponentType()
Return a Class representing the component type IF this class represents an array.
|
Constructor |
getConstructor(Class[] parameterTypes) |
Constructor[] |
getConstructors() |
Class[] |
getDeclaredClasses()
This returns an array of Classes representing all the named inner classes declared by this
class.
|
Constructor |
getDeclaredConstructor(Class[] parameterTypes) |
Constructor[] |
getDeclaredConstructors() |
Field |
getDeclaredField(String name) |
Field[] |
getDeclaredFields() |
Method |
getDeclaredMethod(String name,
Class[] parameterTypes) |
Method[] |
getDeclaredMethods() |
Field |
getField(String name) |
Field[] |
getFields() |
Class[] |
getInterfaces()
Returns an array of interface implemented by this class.
|
Method |
getMethod(String name,
Class[] parameterTypes) |
Method[] |
getMethods() |
int |
getModifiers() |
String |
getName()
Return the name of the class in dot notation (e.g.
|
URL |
getResource(String name)
Return a URL from which a class resource can be read using openStream().
|
InputStream |
getResourceAsStream(String name)
Return an InputStream from which a class resource can be read.
|
Object[] |
getSigners()
This currently always returns an array of zero length as signers are not currently
supported.
|
Class |
getSuperclass()
Return the superclass of the represented class.
|
boolean |
isArray()
Returns true if the class represents an array.
|
boolean |
isAssignableFrom(Class other)
Returns true if the this class is a superclass or superinterface of the specified other class.
|
boolean |
isInstance(Object obj)
This is the equivalent of the instanceof operator.
|
boolean |
isInterface()
Returns true if this class represents an interface.
|
boolean |
isPrimitive()
Checks if this class represents a primitive type.
|
Object |
newInstance() |
String |
toString()
Return a String representation of this object.
|
public String getName()
public String toString()
Object
public ClassLoader getClassLoader()
public static Class forName(String className) throws ClassNotFoundException
To obtain a Class for an array using forName you must provide a name in the form: "[Java_Type" where Java_Type is one of:
'Z' - boolean
'B' - byte
'C' - char
'S' - short
'I' - int
'J' - long
'D' - double
'F' - float
"Lfull_class_name;" - class (e.g.: Ljava.lang.String)
When specifying an array of Objects using "[Lfull_class_name;" if the class full_class_name could not be found a ClassNotFoundException will be thrown.
To get a Class that represents a primitive type use the TYPE field of the appropriate Java wrapper object (e.g. Integer.TYPE).
ClassNotFoundException
public static Class forName(String className, boolean initialize, ClassLoader loader) throws ClassNotFoundException
className
- the name of the class.initialize
- under a Java 1.2 VM this indicates if the Class should be
initialized or not.loader
- the ClassLoader to use. If this is null the System ClassLoader is
used.ClassNotFoundException
- if the class could not be found.public boolean equals(Object other)
Object
public Class getSuperclass()
public Class[] getInterfaces()
public boolean isInterface()
public boolean isAssignableFrom(Class other)
public boolean isInstance(Object obj)
public boolean isPrimitive()
public boolean isArray()
public Class getComponentType()
public Object[] getSigners()
public int getModifiers()
public Class[] getDeclaredClasses()
public Object newInstance() throws InstantiationException, IllegalAccessException
public Field getField(String name) throws NoSuchFieldException, SecurityException
public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException
public Field[] getFields() throws SecurityException
SecurityException
public Field[] getDeclaredFields() throws SecurityException
SecurityException
public Method getMethod(String name, Class[] parameterTypes) throws NoSuchMethodException, SecurityException
public Method[] getMethods() throws SecurityException
SecurityException
public Method getDeclaredMethod(String name, Class[] parameterTypes) throws NoSuchMethodException, SecurityException
public Method[] getDeclaredMethods() throws SecurityException
SecurityException
public Constructor getConstructor(Class[] parameterTypes) throws NoSuchMethodException, SecurityException
public Constructor[] getConstructors() throws SecurityException
SecurityException
public Constructor getDeclaredConstructor(Class[] parameterTypes) throws NoSuchMethodException, SecurityException
public Constructor[] getDeclaredConstructors() throws SecurityException
SecurityException
public URL getResource(String name)
name
- the name of the resource.public InputStream getResourceAsStream(String name)
name
- the name of the resource.