Class ClassUtils
java.lang.Object
com.xebialabs.deployit.booter.local.utils.ClassUtils
Utility methods for dealing with
Classes.- Since:
- 9 Feb 2009
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetActualTypeArguments(Class<? extends S> typedClass, Class<S> typedSuperclass) Retrieves the type arguments of a class when regarded as an subclass of the given typed superclass or interface.
-
Constructor Details
-
ClassUtils
public ClassUtils()
-
-
Method Details
-
getActualTypeArguments
public static <S> List<Class<?>> getActualTypeArguments(Class<? extends S> typedClass, 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 classesclass Foo<U, V> {} class Bar<W> extends Foo<String, W> {} class Baz extends Bar<Long>and atypedClassargument ofBaz.class, the method should return[String, Long]for atypedSuperclassargument ofFoo.class, and[Long]iftypedSuperclassisBar.class.
nullis returned. Note: It is not possible to retrieve type information that is not available in the (super)class hierarchy at compile-time. CallinggetActualTypeArguments(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 superclassAbstractListor the interfaceList. Ifsuperclassis not a superclass or -interface ofclass, the method returnsnull. 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 requiredtypedSuperclass- 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
classis not a subclass ofsuperclass, returnsnull. - Throws:
IllegalArgumentException- iftypedSuperclassortypedClassisnull
-