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

Update java.lang.invoke.MethodHandle to use sealed classes

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • source
    • minimal
    • Since MethodHandle was already not user-subclassable, now it is not user subclassable in a second way.
    • Java API
    • SE

      Summary

      Update MethodHandle to be a sealed class.

      Problem

      The MethodHandle class is not intended to have user-defined subclasses and sealing is an explicit way to indicate this.

      Solution

      Update the class to be declared 'sealed`. Other needed changes are implementation-only and not part of the user-visible API change listed in this CSR.

      Specification

      --- a/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
      +++ b/src/java.base/share/classes/java/lang/invoke/MethodHandle.java
      @@ -440,7 +440,9 @@ mh.invokeExact(System.out, "Hello, world.");
        * @author John Rose, JSR 292 EG
        * @since 1.7
        */
      -public abstract class MethodHandle implements Constable {
      +public abstract sealed class MethodHandle implements Constable
      +    permits NativeMethodHandle, DirectMethodHandle,
      +            DelegatingMethodHandle, BoundMethodHandle {
      
           /**
            * Internal marker interface which distinguishes (to the Java compiler)

            darcy Joe Darcy
            darcy Joe Darcy
            Mandy Chung (Inactive), Sundararajan Athijegannathan
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: