jdk/test/java/lang/invoke/ExplicitCastArgumentsTest.java
changeset 27947 dba3bc0c087e
parent 27196 fe9dbab34d1d
child 32214 7e67ff2f61d4
equal deleted inserted replaced
27946:9f99b93cbbb2 27947:dba3bc0c087e
    30  *
    30  *
    31  * @run main/bootclasspath java.lang.invoke.ExplicitCastArgumentsTest
    31  * @run main/bootclasspath java.lang.invoke.ExplicitCastArgumentsTest
    32  */
    32  */
    33 public class ExplicitCastArgumentsTest {
    33 public class ExplicitCastArgumentsTest {
    34     private static final boolean VERBOSE = Boolean.getBoolean("verbose");
    34     private static final boolean VERBOSE = Boolean.getBoolean("verbose");
       
    35     private static final Class<?> THIS_CLASS = ExplicitCastArgumentsTest.class;
    35 
    36 
    36     public static void main(String[] args) throws Throwable {
    37     public static void main(String[] args) throws Throwable {
       
    38         testVarargsCollector();
       
    39         testRef2Prim();
       
    40         System.out.println("TEST PASSED");
       
    41     }
       
    42 
       
    43     public static String[] f(String... args) { return args; }
       
    44 
       
    45     public static void testVarargsCollector() throws Throwable {
       
    46         MethodType mt = MethodType.methodType(String[].class, String[].class);
       
    47         MethodHandle mh = MethodHandles.publicLookup().findStatic(THIS_CLASS, "f", mt);
       
    48         mh = MethodHandles.explicitCastArguments(mh, MethodType.methodType(Object.class, Object.class));
       
    49         mh.invokeWithArguments((Object)(new String[] {"str1", "str2"}));
       
    50     }
       
    51 
       
    52     public static void testRef2Prim() throws Throwable {
    37         for (Wrapper from : Wrapper.values()) {
    53         for (Wrapper from : Wrapper.values()) {
    38             for (Wrapper to : Wrapper.values()) {
    54             for (Wrapper to : Wrapper.values()) {
    39                 if (from == Wrapper.VOID || to == Wrapper.VOID) continue;
    55                 if (from == Wrapper.VOID || to == Wrapper.VOID) continue;
    40                 testRef2Prim (from, to);
    56                 testRef2Prim(from, to);
    41             }
    57             }
    42         }
    58         }
    43         System.out.println("TEST PASSED");
       
    44     }
    59     }
    45 
    60 
    46     public static void testRef2Prim(Wrapper from, Wrapper to) throws Throwable {
    61     public static void testRef2Prim(Wrapper from, Wrapper to) throws Throwable {
    47         // MHs.eCA javadoc:
    62         // MHs.eCA javadoc:
    48         //    If T0 is a reference and T1 a primitive, and if the reference is null at runtime, a zero value is introduced.
    63         //    If T0 is a reference and T1 a primitive, and if the reference is null at runtime, a zero value is introduced.
    49         test(from.wrapperType(), to.primitiveType(),        null, false);
    64         test(from.wrapperType(), to.primitiveType(), null, false);
    50     }
    65     }
    51 
    66 
    52     public static void test(Class<?> from, Class<?> to, Object param, boolean failureExpected) throws Throwable {
    67     public static void test(Class<?> from, Class<?> to, Object param, boolean failureExpected) throws Throwable {
    53         if (VERBOSE) System.out.printf("%-10s => %-10s: %5s: ", from.getSimpleName(), to.getSimpleName(), param);
    68         if (VERBOSE) System.out.printf("%-10s => %-10s: %5s: ", from.getSimpleName(), to.getSimpleName(), param);
    54 
    69