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

The scope of a class type parameter is too wide

XMLWordPrintable

    • 5.0
    • 5.0
    • b03
    • x86
    • solaris_2.6
    • Verified

        Name: akR10088 Date: 06/09/2004


        The JLS3 Draft 8.1.2 Generic Classes and Type Parameters reads:

        The scope of a class type parameter is the entire declaration of the class,
        except any static members or initializers of the class or of any classes nested within it,
        but including the type parameter section itself. Therefore, type parameters can appear
        as parts of their own bounds, or as bounds of other type parameters declared in the same
        section.

        But the following example shows that not only a class type parameter is visible
        in a static member, but is not shadowed by a nested declaration.

        This test compiles OK:

        ------------------------------ file X.java
        public class X<Z> {

          static public class Y {}

          static public class Y1 <T extends X<Y>> {
          }

        }
        ------------------------
        But if we change in the 1st line "Z" to "Y", this "Y" interfere with the
        name of a nested class:

        ------------------------------ file X.java
        public class X<Y> {

          static public class Y {}

          static public class Y1 <T extends X<Y>> {
          }

        }
        ------------------------
        novo64% javac -source 1.5 X.java
        X.java:5: non-static class Y cannot be referenced from a static context
          static public class Y1 <T extends X<Y>> {
                                              ^
        1 error
        novo64%

        The used JDK version is:

        novo64% java -version
        java version "1.5.0-beta3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b54)
        Java HotSpot(TM) Client VM (build 1.5.0-beta3-b54, mixed mode)


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

              ahe Peter Ahe
              rfqsunw Rfq Rfq (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: