jdk/test/java/lang/invoke/lambda/T8032697.java
changeset 22609 4c76e9557a15
equal deleted inserted replaced
22608:55902b6456fa 22609:4c76e9557a15
       
     1 /*
       
     2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @bug 8032697
       
    27  * @summary Issues with Lambda
       
    28  */
       
    29 
       
    30 import java.lang.invoke.LambdaMetafactory;
       
    31 import java.lang.invoke.LambdaConversionException;
       
    32 import java.lang.invoke.MethodHandle;
       
    33 import java.lang.invoke.MethodHandles;
       
    34 import java.lang.invoke.MethodType;
       
    35 
       
    36 import T8032697_anotherpkg.T8032697_A;
       
    37 
       
    38 public class T8032697 extends T8032697_A {
       
    39 
       
    40     interface I {
       
    41         int m();
       
    42     }
       
    43 
       
    44     interface IA {
       
    45         int m(T8032697_A x);
       
    46     }
       
    47 
       
    48     static MethodHandles.Lookup l;
       
    49     static MethodHandle h;
       
    50     private static MethodType mt(Class<?> k) { return MethodType.methodType(k); }
       
    51     private static MethodType mt(Class<?> k, Class<?> k2) { return MethodType.methodType(k, k2); }
       
    52     private static boolean mf(MethodType mti, MethodType mtf) {
       
    53         try {
       
    54             LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);
       
    55         } catch(LambdaConversionException e) {
       
    56             return true;
       
    57         }
       
    58         return false;
       
    59     }
       
    60 
       
    61     public static void main(String[] args) throws Throwable {
       
    62         l = MethodHandles.lookup();
       
    63         h = l.findVirtual(T8032697_A.class, "f", mt(int.class));
       
    64         if (mf(mt(I.class, T8032697.class), mt(int.class))) throw new AssertionError("Error: Should work");
       
    65         if (mf(mt(IA.class), mt(int.class, T8032697.class))) throw new AssertionError("Error: Should work");
       
    66         if (!mf(mt(I.class, T8032697_A.class), mt(int.class))) throw new AssertionError("Error: Should fail");
       
    67         if (!mf(mt(IA.class), mt(int.class, T8032697_A.class))) throw new AssertionError("Error: Should fail");
       
    68     }
       
    69 }