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

Private member of type variable wrongly accesible

XMLWordPrintable

    • generic
    • generic

      This program compiles:

      class T<X extends T<X>> {
          private int t = 123;
          {
              X x = null;
              x.t = 456; // X inherits private member t? Not according to JLS
          }
      }

      According to the JLS 4.4 (Type Variables) the members of
      a type variable are the same as the intersection type 4.9
      (Intersection Types), meaning that this is equivalent:

      class T {
          private int t = 123;
          {
              class X extends T {}
              X x = null;
              x.t = 456;
          }
      }

      This program doesn't compile.

      ###@###.### 2005-03-28 19:33:39 GMT

            mcimadamore Maurizio Cimadamore
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: