|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.meta.reflect.TypeLiteral<T> dk.rode.thesis.meta.reflect.InstantiableTypeLiteral<T>
T
- The type represented by this instantiable type literal.public abstract class InstantiableTypeLiteral<T>
Represents the instantiable type realised as the type
parameter T
, where T
may be a generic type.
New instances of T
can be created using the
newInstance(Object...)
method. Hence, interfaces
and abstract classes cannot be used as the raw type
of T
.
The constructor to create new instances of T
is
fetched ignoring primitive types, e.g. a formal parameter type
of Integer
will match both Integer
and int
.
TypeLiteral
Field Summary | |
---|---|
private Constructor<?> |
constructor
The constructor used to create new instances of the type represented by the type parameter T . |
Fields inherited from class dk.rode.thesis.meta.reflect.TypeLiteral |
---|
type |
Constructor Summary | |
---|---|
protected |
InstantiableTypeLiteral(Class<?>... parameterTypes)
Constructor, which creates this instantiable type literal to represent the type realised by the type parameter T . |
|
InstantiableTypeLiteral(InstantiableTypeLiteral<T> typeLiteral)
Copy constructor, which creates this instantiable type literal based on the generic type and constructor represented by typeLiteral |
private |
InstantiableTypeLiteral(TypeLiteral<T> typeLiteral,
Class<?>... parameterTypes)
Constructor, which creates this instantiable type literal to represent the type represented by the type literal typeLiteral . |
Method Summary | ||
---|---|---|
static
|
create(Class<S> clazz,
Class<?>... parameterTypes)
Returns an instantiable type literal representing the type S supplied via the class literal clazz . |
|
static InstantiableTypeLiteral<?> |
create(Type type,
Class<?>... parameterTypes)
Returns a instantiable type literal representing the type supplied as type . |
|
static
|
create(TypeLiteral<S> typeLiteral,
Class<?>... parameterTypes)
Returns an instantiable type literal representing the type S supplied via the type literal type . |
|
boolean |
equals(Object object)
Returns true of object is an instantiable type literal
representing the same type and constructor
as this instantiable type literal, false if not. |
|
Constructor<?> |
getConstructor()
Return the constructor represented by this instantiable type literal. |
|
private static Constructor<?> |
getConstructor(Type type,
Class<?>... parameterTypes)
Returns the constructor having the formal parameter types supplied as parameterTypes in the raw type
fetched from type . |
|
static boolean |
isInstatiable(Type type)
Returns true if the raw type represented by type
is instantiable, false if not. |
|
static boolean |
isInstatiable(TypeLiteral<?> type)
Returns true if the raw type represented by type
is instantiable, false if not. |
|
T |
newInstance(Object... arguments)
Returns a new instance of the type represented by this instantiable type literal. |
Methods inherited from class dk.rode.thesis.meta.reflect.TypeLiteral |
---|
asClass, asClass, asType, create, create, create, getComponentType, getRawType, getRawType, getType, hashCode, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private final Constructor<?> constructor
T
. The constructor is identified by its formal parameter types supplied at construction time.
Never null.
Constructor Detail |
---|
protected InstantiableTypeLiteral(Class<?>... parameterTypes) throws NoSuchMethodException
T
.
New instances of T
can be created
using the declared constructor having the formal parameter
types supplied parameterTypes
.
The constructor is made accessible if not already.
parameterTypes
- The formal parameter types for the
declared constructor to use.
IllegalArgumentException
- If this class is not generic, if
T
has no raw type, or if the raw raw represents
a non instantiable class.
NoSuchMethodException
- If no such constructor is declared in
the raw type of T
.public InstantiableTypeLiteral(InstantiableTypeLiteral<T> typeLiteral)
typeLiteral
typeLiteral
- The instantiable type literal to copy; cannot be null.
NullPointerException
- If typeLiteral
is null.private InstantiableTypeLiteral(TypeLiteral<T> typeLiteral, Class<?>... parameterTypes) throws NoSuchMethodException
typeLiteral
.
New instances of T
can be created
using the declared constructor having the formal parameter
types supplied parameterTypes
.
The constructor is made accessible if not already.
typeLiteral
- The type literal; cannot be null.parameterTypes
- The formal parameter types for the
declared constructor to use.
IllegalArgumentException
- If this class is not generic, if
T
has no raw type, or if the raw raw represents
a non instantiable class.
NoSuchMethodException
- If no such constructor is declared in
the raw type of T
.Method Detail |
---|
public static <S> InstantiableTypeLiteral<S> create(Class<S> clazz, Class<?>... parameterTypes) throws NoSuchMethodException
S
supplied via the class literal clazz
.
The declared constructor to use is identified by the formal
parameter types supplied as parameterTypes
. The
constructor is made accessible if not already.
S
- The type.clazz
- The class literal representing the type;
cannot be null.parameterTypes
- The formal parameter types for the declared
constructor to use.
S
;
never null.
NullPointerException
- If clazz
is null.
IllegalArgumentException
- If S
is a non-instantiable
type.
NoSuchMethodException
- If no such constructor is declared in
the raw type of S
.create(Type, Class...)
,
create(TypeLiteral, Class...)
,
isInstatiable(Type)
public static InstantiableTypeLiteral<?> create(Type type, Class<?>... parameterTypes) throws NoSuchMethodException
type
.
The declared constructor to use is identified by the formal
parameter types supplied as parameterTypes
. The
constructor is made accessible if not already.
type
- The type; cannot be null.parameterTypes
- The formal parameter types for the declared
constructor to use.
NullPointerException
- If type
is null.
IllegalArgumentException
- If type
represents a
non-instantiable type.
NoSuchMethodException
- If no such constructor is declared in
the raw type of type
.create(Class, Class...)
,
create(TypeLiteral, Class...)
,
isInstatiable(Type)
public static <S> InstantiableTypeLiteral<S> create(TypeLiteral<S> typeLiteral, Class<?>... parameterTypes) throws NoSuchMethodException
S
supplied via the type literal type
.
The declared constructor to use is identified by the formal
parameter types supplied as parameterTypes
. The
constructor is made accessible if not already.
S
- The type.typeLiteral
- The type literal representing the type;
cannot be null.parameterTypes
- The formal parameter types for the declared
constructor to use.
S
;
never null.
NullPointerException
- If typeLiteral
is null.
IllegalArgumentException
- If typeLiteral
represents a
non-instantiable type.
NoSuchMethodException
- If no such constructor is declared in
the raw type of S
.create(Class, Class...)
,
create(Type, Class...)
,
isInstatiable(TypeLiteral)
public boolean equals(Object object)
object
is an instantiable type literal
representing the same type
and constructor
as this instantiable type literal, false if not.
equals
in class TypeLiteral<T>
object
- The object to test; can be null.
public Constructor<?> getConstructor()
TypeLiteral.getType()
private static final Constructor<?> getConstructor(Type type, Class<?>... parameterTypes) throws NoSuchMethodException
parameterTypes
in the raw type
fetched from type
. The constructor is made accessible if not already.
type
- The type; cannot be null.parameterTypes
- The formal parameter types.
NullPointerException
- If type
is null.
IllegalArgumentException
- If T
has no raw type,
or if the raw type represents an interface or abstract class.
NoSuchMethodException
- If no such constructor is declared in
the raw type.Reflection.getConstructor(Class, Class...)
public static boolean isInstatiable(Type type)
type
is instantiable, false if not.
If no raw exist based on type
or if the raw type
is abstract or an interface, false is returned. Otherwise
type.
This method does not test for explicit constructors.
type
- The type to test; cannot be null.
NullPointerException
- If type
is null.public static boolean isInstatiable(TypeLiteral<?> type)
type
is instantiable, false if not.
If no raw exist based on type
or if the raw type
is abstract or an interface, false is returned. Otherwise
type.
This method does not test for explicit constructors.
type
- The type to test; cannot be null.
NullPointerException
- If type
is null.public T newInstance(Object... arguments) throws Exception
arguments
- The arguments to supply to the constructor.
Exception
- If the construction fails.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |