com.xebialabs.deployit.booter.local.utils
Class ClassUtils

java.lang.Object
  extended by com.xebialabs.deployit.booter.local.utils.ClassUtils

public class ClassUtils
extends java.lang.Object

Utility methods for dealing with Classes.

Since:
9 Feb 2009

Constructor Summary
ClassUtils()
           
 
Method Summary
static
<S> java.util.List<java.lang.Class<?>>
getActualTypeArguments(java.lang.Class<? extends S> typedClass, java.lang.Class<S> typedSuperclass)
          Retrieves the type arguments of a class when regarded as an subclass of the given typed superclass or interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassUtils

public ClassUtils()
Method Detail

getActualTypeArguments

public static <S> java.util.List<java.lang.Class<?>> getActualTypeArguments(java.lang.Class<? extends S> typedClass,
                                                                            java.lang.Class<S> typedSuperclass)
Retrieves the type arguments of a class when regarded as an subclass of the given typed superclass or interface. The order of the runtime type classes matches the order of the type variables in the declaration of the typed superclass or interface.

For example, for the classes

 class Foo<U, V> {}
 class Bar<W> extends Foo<String, W> {}
 class Baz extends Bar<Long>
 

and a typedClass argument of Baz.class, the method should return

For type parameters that cannot be determined, null is returned.

Note: It is not possible to retrieve type information that is not available in the (super)class hierarchy at compile-time. Calling getActualTypeArguments(new ArrayList<String>().getClass(), List.class) will, for instance, return [null] because the specification of the actual type (String, in this example) did not take place either in the superclass AbstractList or the interface List.

If superclass is not a superclass or -interface of class, the method returns null. This may happen (in spite of the signature) if the method is called with non-generic arguments.

Type Parameters:
S - the type of the object
Parameters:
typedClass - the class for which type information is required
typedSuperclass - the typed class or interface of which the object is to be regarded a subclass
Returns:
the type arguments for the given class when regarded as a subclass of the given typed superclass, in the order defined in the superclass. If class is not a subclass of superclass, returns null.
Throws:
java.lang.IllegalArgumentException - if typedSuperclass or typedClass is null