public class MetaClass<T>
extends java.lang.Object
MetaClass
describes a real Class
with the purpose
of providing to an IDE class level information, and delaying the loading of
that class to the last possible moment: when an instance of the class is
required.
A MetaClass
binds the Class
object from its class name
using the appropriate class loader. Once the class is bound, new instances
can be created using the newInstance()
method.
Constructor and Description |
---|
MetaClass(java.lang.ClassLoader classLoader,
java.lang.String className)
Construct a meta class for the specified class name.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object object) |
java.lang.ClassLoader |
getClassLoader()
Get the classloader for this meta class.
|
java.lang.String |
getClassName()
Get the fully qualified class name.
|
int |
hashCode() |
T |
newInstance()
Creates a new instance of the class represented by this
MetaClass object. |
static <N> MetaClass<N> |
newMetaClass(java.lang.Class<N> clazz)
Construct a meta class given a class already classloaded.
|
java.lang.Class |
toClass()
Build the
Class object from the class name. |
java.lang.Class |
toClass(boolean triggerTopmostClassLoader) |
java.lang.String |
toString() |
public MetaClass(java.lang.ClassLoader classLoader, java.lang.String className)
classLoader
- the class loader to load the class from. Must not be
null.className
- the fully qualified name of the class. Must not be null.public static <N> MetaClass<N> newMetaClass(java.lang.Class<N> clazz)
clazz,
- the classpublic java.lang.String getClassName()
Class
instance.public java.lang.ClassLoader getClassLoader()
public java.lang.Class toClass() throws java.lang.ClassNotFoundException
Class
object from the class name. Uses the right
class loader in doing so.Class
object.java.lang.ClassNotFoundException
- if the class was not found.public java.lang.Class toClass(boolean triggerTopmostClassLoader) throws java.lang.ClassNotFoundException
java.lang.ClassNotFoundException
public T newInstance() throws java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.ClassNotFoundException
MetaClass
object.java.lang.IllegalAccessException
- if the Class
or its
initializer is not accessible.java.lang.InstantiationException
- if the Class
is an
abstract class, an interface, an array class, a primitive type, or
void; or if the instantiation fails for some other reason.java.lang.ClassNotFoundException
- if the Class
is not found
using the MetaClass
name.java.lang.ClassCastException
- if the Class
is of the wrong type.public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object object)
equals
in class java.lang.Object