|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.fest.reflect.type.Type
public final class Type
Understands loading a class dynamically.
The following is an example of proper usage of this class:
// Loads the class 'org.republic.Jedi' Class<?> jediType =type("org.republic.Jedi").load(); // Loads the class 'org.republic.Jedi' as 'org.republic.Person' (Jedi extends Person) Class<Person> jediType =type("org.republic.Jedi").loadAs(Person.class); // Loads the class 'org.republic.Jedi' using a custom class loader Class<?> jediType =type("org.republic.Jedi").withClassLoader(myClassLoader).load();
| Method Summary | ||
|---|---|---|
Class<?> |
load()
Loads the class with the name specified in this type, using this class' ClassLoader. |
|
|
loadAs(Class<T> type)
Loads the class with the name specified in this type, as the given type, using this class' ClassLoader. |
|
static Type |
newType(String name)
Creates a new : the starting point of the fluent interface for loading classes
dynamically. |
|
TypeLoader |
withClassLoader(ClassLoader classLoader)
Specifies the to use to load the class. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static Type newType(String name)
Type: the starting point of the fluent interface for loading classes
dynamically.
name - the name of the class to load.
Type.
NullPointerException - if the given name is null.
IllegalArgumentException - if the given name is empty.public Class<?> load()
ClassLoader.
ReflectionError - wrapping any error that occurred during class loading.public <T> Class<? extends T> loadAs(Class<T> type)
ClassLoader.
The following example shows how to use this method. Let's assume that we have the class Jedi that
extends the class Person:
Class<Person> type =type("org.republic.Jedi").loadAs(Person.class);
T - the generic type of the type.type - the given type.
NullPointerException - if the given type is null.
ReflectionError - wrapping any error that occurred during class loading.public TypeLoader withClassLoader(ClassLoader classLoader)
ClassLoader to use to load the class.
Example:
Class<?> type =type("org.republic.Jedi").withClassLoader(myClassLoader).load();
classLoader - the given ClassLoader.
ClassLoader.
NullPointerException - if the given ClassLoader is null.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||