Class TypeReflectionUtils

java.lang.Object
org.axonframework.common.TypeReflectionUtils

public final class TypeReflectionUtils extends Object
Utility class for doing reflection on types.

This TypeReflectionUtils is a trimmed down copy of the com.googlecode.gentyref.GenericTypeReflector. All the unused functions have been removed and only the getExactSuperType(Type, Class) has remained. The private functions used by getExactSuperType(Type, Class) have also been tailored to our exact needs.

The credits for creating this functionality however go to Wouter Coekaerts, which created this functionality in the 'com.googlecode.gentyref' library with group id 'gentyref'.
Since:
3.2
Author:
Wouter Coekaerts invalid input: '<'wouter@coekaerts.be>, Steven van Beelen
  • Method Details

    • getExactSuperType

      public static Type getExactSuperType(Type type, Class<?> searchClass)
      Finds the most specific supertype of type whose erasure is searchClass. In other words, returns a type representing the class searchClass plus its exact type parameters in type.

      • Returns an instance of ParameterizedType if searchClass is a real class or interface and type has parameters for it
      • Returns an instance of GenericArrayType if searchClass is an array type, and type has type parameters for it
      • Returns an instance of Class if type is a raw type, or has no type parameters for searchClass
      • Returns null if searchClass is not a superclass of type.

      For example, with class StringList implements List<String>, getExactSuperType(StringList.class, Collection.class) returns a ParameterizedType representing Collection<String>.

      Parameters:
      type - The type to search
      searchClass - The erased type of the super class to find
      Returns:
      The supertype of type, whose erased type is searchClass