Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6202725

(reflect) java.lang.reflect.GenericArrayType is found where byte[].class was expected

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 5.0
    • core-libs
    • None


      The javadoc of GenericArrayType says it's a Type object for arrays whose
      component type is either a parameterized type or a type variable.

      The following code shows that the JRE creates GenericArrayType whose component
      type is a Class object (Byte.TYPE)

      The javadoc and the implementation are disagreeing with each other.

      ================================

      import java.util.List;
      import java.lang.reflect.Field;
      import java.lang.reflect.Type;
      import java.lang.reflect.ParameterizedType;

      public class GenericsTest {
          public static void main(String[] args) throws Exception {
              Field f = GenericsTest.class.getField("lst");
              Type t1 = f.getGenericType();
              assert t1 instanceof ParameterizedType;
              ParameterizedType t2 = (ParameterizedType) t1;
              assert t2.getActualTypeArguments().length==1;
              Type t3 = t2.getActualTypeArguments()[0];
              assert t3==byte[].class : "expected byte[] but found "+t3.getClass();
          }

          public List<byte[]> lst;
      }
      ==============


            darcy Joe Darcy
            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: