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

[lworld] Trouble assigning/casting to a value array type with parameterized element type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • repo-valhalla
    • repo-valhalla
    • tools
    • generic
    • generic

      The following code does not compile: (reported by Sergey Kuksenko)

      public class X {

      public value class Value<T> {
      T t = null;

      void foo() {
      Value<T>[] v = (Value<T>[]) new Value[1024];
      }
      }
      }

      A similar problem was also reported by Remi with this construct:

      This code doesn't compile anymore:
      public class Regression {
         static value class Entry<E> {
           private final int value;

           public Entry(int value) {
             this.value = value;
           }
                public static <E> Entry<E>[] of() {
             return (Entry<E>[])new Entry<?>[0];
           }
         }
            public static void main(String[] args) {
           var entry = Entry.of();
         }
      }

            sadayapalam Srikanth Adayapalam (Inactive)
            sadayapalam Srikanth Adayapalam (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: