Package org.glassfish.gmbal.util
Class GenericConstructor<T>
java.lang.Object
org.glassfish.gmbal.util.GenericConstructor<T>
Class that allows any class to be instantiated via any accessible constructor.
Really a short hand to avoid writing a bunch of reflective code.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Constructor
private final Object
private Class<?>[]
private Class
<?> private String
-
Constructor Summary
ConstructorsConstructorDescriptionGenericConstructor
(Class<T> type, String className, Class<?>... signature) Create a generic of type T for the untyped class cls. -
Method Summary
Modifier and TypeMethodDescriptionCreate an instance of type T using the constructor that matches the given arguments if possible.private void
-
Field Details
-
lock
-
typeName
-
resultType
-
type
-
signature
-
constructor
-
-
Constructor Details
-
GenericConstructor
Create a generic of type T for the untyped class cls. Generally cls is a class that has been generated and loaded, so no compiled code can depend on the class directly. However, the generated class probably implements some interface T, represented here byClass<T>
.- Parameters:
type
- The expected type of a create call.className
- The name of the class to use for a constructor.signature
- The signature of the desired constructor.- Throws:
IllegalArgumentException
- if cls is not a subclass of type.
-
-
Method Details
-
getConstructor
private void getConstructor() -
create
Create an instance of type T using the constructor that matches the given arguments if possible. The constructor is cached, so an instance of GenericClass should always be used for the same types of arguments. If a call fails, a check is made to see if a different constructor could be used.- Parameters:
args
- The constructor arguments.- Returns:
- A new instance of the object.
-