jdk/src/java.base/share/classes/java/lang/invoke/SimpleMethodHandle.java
changeset 26472 71b6a6f208c0
parent 26470 1586df597397
equal deleted inserted replaced
26471:1de6be0c6945 26472:71b6a6f208c0
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 
    25 
    26 package java.lang.invoke;
    26 package java.lang.invoke;
    27 
    27 
       
    28 import static java.lang.invoke.LambdaForm.BasicType.*;
       
    29 import static java.lang.invoke.MethodHandleStatics.*;
       
    30 
    28 /**
    31 /**
    29  * A method handle whose behavior is determined only by its LambdaForm.
    32  * A method handle whose behavior is determined only by its LambdaForm.
    30  * @author jrose
    33  * @author jrose
    31  */
    34  */
    32 final class SimpleMethodHandle extends MethodHandle {
    35 final class SimpleMethodHandle extends BoundMethodHandle {
    33     private SimpleMethodHandle(MethodType type, LambdaForm form) {
    36     private SimpleMethodHandle(MethodType type, LambdaForm form) {
    34         super(type, form);
    37         super(type, form);
    35     }
    38     }
    36 
    39 
    37     /*non-public*/ static SimpleMethodHandle make(MethodType type, LambdaForm form) {
    40     /*non-public*/ static BoundMethodHandle make(MethodType type, LambdaForm form) {
    38         return new SimpleMethodHandle(type, form);
    41         return new SimpleMethodHandle(type, form);
    39     }
    42     }
    40 
    43 
       
    44     /*non-public*/ static final SpeciesData SPECIES_DATA = SpeciesData.EMPTY;
       
    45 
       
    46     /*non-public*/ public SpeciesData speciesData() {
       
    47             return SPECIES_DATA;
       
    48     }
       
    49 
    41     @Override
    50     @Override
    42     /*non-public*/ SimpleMethodHandle copyWith(MethodType mt, LambdaForm lf) {
    51     /*non-public*/ BoundMethodHandle copyWith(MethodType mt, LambdaForm lf) {
    43         return make(mt, lf);
    52         return make(mt, lf);
    44     }
    53     }
       
    54 
       
    55     @Override
       
    56     String internalProperties() {
       
    57         return "\n& Class="+getClass().getSimpleName();
       
    58     }
       
    59 
       
    60     @Override
       
    61     /*non-public*/ public int fieldCount() {
       
    62         return 0;
       
    63     }
       
    64 
       
    65     @Override
       
    66     /*non-public*/ final BoundMethodHandle copyWithExtendL(MethodType mt, LambdaForm lf, Object narg) {
       
    67         return BoundMethodHandle.bindSingle(mt, lf, narg); // Use known fast path.
       
    68     }
       
    69     @Override
       
    70     /*non-public*/ final BoundMethodHandle copyWithExtendI(MethodType mt, LambdaForm lf, int narg) {
       
    71         try {
       
    72             return (BoundMethodHandle) SPECIES_DATA.extendWith(I_TYPE).constructor().invokeBasic(mt, lf, narg);
       
    73         } catch (Throwable ex) {
       
    74             throw uncaughtException(ex);
       
    75         }
       
    76     }
       
    77     @Override
       
    78     /*non-public*/ final BoundMethodHandle copyWithExtendJ(MethodType mt, LambdaForm lf, long narg) {
       
    79         try {
       
    80             return (BoundMethodHandle) SPECIES_DATA.extendWith(J_TYPE).constructor().invokeBasic(mt, lf, narg);
       
    81         } catch (Throwable ex) {
       
    82             throw uncaughtException(ex);
       
    83         }
       
    84     }
       
    85     @Override
       
    86     /*non-public*/ final BoundMethodHandle copyWithExtendF(MethodType mt, LambdaForm lf, float narg) {
       
    87         try {
       
    88             return (BoundMethodHandle) SPECIES_DATA.extendWith(F_TYPE).constructor().invokeBasic(mt, lf, narg);
       
    89         } catch (Throwable ex) {
       
    90             throw uncaughtException(ex);
       
    91         }
       
    92     }
       
    93     @Override
       
    94     /*non-public*/ final BoundMethodHandle copyWithExtendD(MethodType mt, LambdaForm lf, double narg) {
       
    95         try {
       
    96             return (BoundMethodHandle) SPECIES_DATA.extendWith(D_TYPE).constructor().invokeBasic(mt, lf, narg);
       
    97         } catch (Throwable ex) {
       
    98             throw uncaughtException(ex);
       
    99         }
       
   100     }
    45 }
   101 }