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

(reflect) Class.getEnclosingClass - api to get outer enclosing class

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Not an Issue
    • P4
    • None
    • 1.4.1
    • core-libs

    Description



      Name: gm110360 Date: 07/18/2003


      A DESCRIPTION OF THE REQUEST :
      There is no clean way to determine the enclosing classes of an inner class.
      When reflectively creating a class (that might be inner) you would have to determine if the class is inner and if it is, is it static, then if the class is inner and not static you must construct the class passing in the outclass as a parameter. You must know where to pass it in (in the front or in the back).

      JUSTIFICATION :
      Lets say you create an action wrapper that takes an action and regesters it so it can latter create a button, menu Item, ect... Multiple instances of the action may be necessary and creating it in different ways can be helpful on a per-situation basis. The action may come as part of an inner class or an outer class, there needs to be an easy way to determine if it is an inner class and if it is create it with the appropiate outer class pointer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      new method in java.lang.Class:
      public Class getEnclosingClass()

      returns the Enclosing Class of this class or null if it is the outest most class.

      new method in java.lang.reflect.Constructor:
      public Object newInstance(Object enclosingClass,Object[] parameters)

      returns a new instance of an inner class for the enclosing class.
      ACTUAL -
      These methods do not exits.

      CUSTOMER SUBMITTED WORKAROUND :
      A user can "guess" the enclosing class by:
      String name = class.getName();
      Class enclosingClass = Class.forName(name.substring(name.lastIndexOf("$")));
      (Incident Review ID: 186775)
      ======================================================================

      Attachments

        Issue Links

          Activity

            People

              iris Iris Clark
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: