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

Allow subclassing Java classes from script without creating instances

    XMLWordPrintable

Details

    • Enhancement
    • Status: Resolved
    • P2
    • Resolution: Fixed
    • None
    • 8
    • core-libs
    • None

    Description

      Currently, the only way to subclass a Java class in Nashorn is to create an instance a la anonymous inner classes in Java:

          var r = new java.lang.Runnable() {
              run: function() { ... }
          }

      However, sometimes we need to create a subclass without creating instances. We'd need a functionality like:

          var R = Java.extend(java.lang.Runnable, {
              run: function() { ... }
          })

      Such a class can then be instantiated:

         var r = new R

      Or passed to some other API, i.e.:

        launch(R.class)

      Attachments

        Activity

          People

            attila Attila Szegedi
            attila Attila Szegedi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: