Class TypeUtil


  • public class TypeUtil
    extends Object
    Type arithmetic code. Taken from the JAXB RI.
    Author:
    Kohsuke Kawaguchi
    • Constructor Detail

      • TypeUtil

        public TypeUtil()
    • Method Detail

      • erasure

        public static <T> Class<T> erasure​(Type t)
        Returns the runtime representation of the given type. This corresponds to the notion of the erasure in JSR-14.
      • getBaseClass

        public static Type getBaseClass​(Type type,
                                        Class baseType)
        Gets the parameterization of the given base type.

        For example, given the following

        
         interface Foo<T> extends List<List<T>> {}
         interface Bar extends Foo<String> {}
         
        This method works like this:
        
         getBaseClass( Bar, List ) = List<List<String>
         getBaseClass( Bar, Foo  ) = Foo<String>
         getBaseClass( Foo<? extends Number>, Collection ) = Collection<List<? extends Number>>
         getBaseClass( ArrayList<? extends BigInteger>, List ) = List<? extends BigInteger>
         
        Parameters:
        type - The type that derives from baseType
        baseType - The class whose parameterization we are interested in.
        Returns:
        The use of baseType in type. or null if the type is not assignable to the base type.
      • getTypeArgument

        public static Type getTypeArgument​(Type type,
                                           int i)