Code example for GenericArrayType

Methods: getGenericComponentType

  private static Type extractSecondLevelType(Type actualType, Class<?> rawClass) {
    if (actualType instanceof GenericArrayType) {
      GenericArrayType castedType = (GenericArrayType) actualType;
      return castedType.getGenericComponentType();
    } else { 
      return rawClass.getComponentType();
   * @return the raw type unwrapped of the second level of array. 
   * If the object is (single-dimensional or multi-dimensional) array, it is the class of the 
   * elements of the array. For example, this method returns Foo.class for Foo[]. 
   * It will return Foo[].class for Foo[][].  For Foo&lt;String&gt;[][] types, it will return the  
   * type representing Foo&lt;String&gt;[]  
   * (i.e. <code>new TypeToken<Foo<String>[]>() {}.getType()</code>). 
  public Type getSecondLevelType() {
    return secondLevel;