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

Allow static anonymous classes

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P5
    • None
    • 6
    • tools
    • x86
    • windows_xp

    Description

      A DESCRIPTION OF THE REQUEST :
      Currently, it is impossible to create an anonymous class that doesn't reference its outer class through some variable like this$0. I would like to see this possible:

          new static A() { ... }

      which would work just like:

          new A() { ... }

      except that the anonymous inner class could not access the enclosing class.

      JUSTIFICATION :
      The static anonymous inner class would be more efficient to construct for classes which don't access their outer defining class AND the static anonymous inner class would not reference the outer class... which is a huge advantage in restricting reachability-sensitive technologies like serialization.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Creates a static anonymous class that does not permit access to enclosing classes through this pointers.
      ACTUAL -
      Feature does not exist.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Imported:
                Indexed: