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

generic type arrays aren't allowed

XMLWordPrintable

    • rc
    • sparc
    • solaris_8



      Name: ngR10089 Date: 01/27/2004


       
      javac (jdk1.5.0-b35) doesn't allow arrays of generic types.

      The latest spec of "Adding Generics to the Java Programming Language: Public
      Draft Specification, Version 2.0" say nothing about forbidden generic type
      array creation.
      More over it reads:

          5.3 Array Creation Expressions

          The element type in an array creation expression is a fully parameterized
          type. Creating an array whose element type is a type variable generates an
          unchecked warning at compile-time.
          
          Syntax (see JLS, Sec. 15.10)

          ArrayCreationExpression ::= new PrimitiveType DimExprs DimsOpt
                                    | new ClassOrInterfaceType DimExprs DimsOpt
                                    | new PrimitiveType Dims ArrayInitializer
                                    | new ClassOrInterfaceType Dims ArrayInitializer


      However javac (jdk1.5.0-b35) reports errors compiling test below.

      > java -version
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b35)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b35, mixed mode)
      novo41%

      > javac -d . -source 1.5 expr67201.java
      expr67201.java:27: arrays of generic types are not allowed
              expr67201a<Integer>[] vi = new expr67201a<Integer>[10];
                                 ^
      expr67201.java:27: arrays of generic types are not allowed
              expr67201a<Integer>[] vi = new expr67201a<Integer>[10];
                                         ^
      expr67201.java:30: arrays of generic types are not allowed
              expr67201a<String>[] vs = {new expr67201a<String>("Test0"),
                                ^
      3 errors
      >

      --------------- expr67201.java-------------
      package javasoft.sqe.tests.lang.expr672.expr67201;
      import java.io.PrintStream;

      class expr67201a<A>{
          A value;
          expr67201a(A value) {
              this.value = value;
          }
          expr67201a() {
          }
      }

      public class expr67201 {
          public static void main(String argv[]) {
              System.exit(run(argv, System.out) + 95/*STATUS_TEMP*/);
          }
          public static int run(String argv[],PrintStream out) {
              boolean result = true;
              expr67201a<Integer>[] vi = new expr67201a<Integer>[10];
              for(int i = 0; i < 2; i++)
                  vi[i] = new expr67201a<Integer>(new Integer(i));
              expr67201a<String>[] vs = {new expr67201a<String>("Test0"),
                      new expr67201a<String>("Test1")};
              for(int i = 0; i < 2; i++)
                  if(vi[i].value.intValue() != i || !vs[i].value.equals("Test" + i))
                      result = false;
              if(result)
                  return 0/*STATUS_PASSED*/;
              return 2/*STATUS_FAILED*/;
          }
      }
      ---------------------------------------

      Some new JCK tests fail due to this bug.


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

            gbrachasunw Gilad Bracha (Inactive)
            nvgsunw Nvg Nvg (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: