org.glassfish.pfl.dynamic.codegen.spi
Class GenericClass<T>

java.lang.Object
  extended by org.glassfish.pfl.dynamic.codegen.spi.GenericClass<T>

public class GenericClass<T>
extends Object

Class that allows any class to be instantiated via any accessible constructor. Really a short hand to avoid writing a bunch of reflective code.


Constructor Summary
GenericClass(Class<T> type, Class<?> cls)
          Create a generic of type T for the untyped class cls.
GenericClass(Class<T> type, InterceptorContext ic, byte[] classData)
          Create a GenericClass of the given type by modifying classData with the given interceptors.
 
Method Summary
 T create(Object... args)
          Create an instance of type T using the constructor that matches the given arguments if possible.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GenericClass

public GenericClass(Class<T> type,
                    InterceptorContext ic,
                    byte[] classData)
Create a GenericClass of the given type by modifying classData with the given interceptors. XXX we may need a constructor that specifies the ClassLoader, etc.


GenericClass

public GenericClass(Class<T> type,
                    Class<?> cls)
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 by Class.

Throws:
IllegalArgumentException - if cls is not a subclass of type.
Method Detail

create

public T create(Object... args)
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.



Copyright © 2013 Oracle. All Rights Reserved.