Class TypeArguments


  • public final class TypeArguments
    extends java.lang.Object
    Utility methods for dealing with generic type arguments.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.reflect.Type[] NO_TYPES  
      private static java.lang.reflect.Type OBJECT_TYPE  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TypeArguments()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.reflect.Type expand​(java.lang.reflect.Type type)
      Expands wild-card types where possible, for example Bar from ? extends Bar.
      static java.lang.reflect.Type[] get​(java.lang.reflect.Type type)
      Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.
      static java.lang.reflect.Type get​(java.lang.reflect.Type type, int index)
      Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.
      static java.lang.Class<?> getRawType​(java.lang.reflect.Type type)
      Get the erased raw Class for a generic type, for example Map from Map<Foo,Bar>.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • OBJECT_TYPE

        private static final java.lang.reflect.Type OBJECT_TYPE
      • NO_TYPES

        private static final java.lang.reflect.Type[] NO_TYPES
    • Constructor Detail

      • TypeArguments

        private TypeArguments()
    • Method Detail

      • get

        public static java.lang.reflect.Type[] get​(java.lang.reflect.Type type)
        Get all type arguments from a generic type, for example [Foo,Bar] from Map<Foo,Bar>.
        Parameters:
        type - The generic type
        Returns:
        Array of type arguments
      • get

        public static java.lang.reflect.Type get​(java.lang.reflect.Type type,
                                                 int index)
        Get an indexed type argument from a generic type, for example Bar from Map<Foo,Bar>.
        Parameters:
        type - The generic type
        index - The argument index
        Returns:
        Indexed type argument; Object.class if the given type is a raw class
      • getRawType

        public static java.lang.Class<?> getRawType​(java.lang.reflect.Type type)
        Get the erased raw Class for a generic type, for example Map from Map<Foo,Bar>.
        Parameters:
        type - The generic type
        Returns:
        Erased raw type
      • expand

        private static java.lang.reflect.Type expand​(java.lang.reflect.Type type)
        Expands wild-card types where possible, for example Bar from ? extends Bar.
        Parameters:
        type - The generic type
        Returns:
        Widened type that is still assignment-compatible with the original.