Path: blob/jdk8u272-b10-aarch32-20201026/jdk/test/java/lang/invoke/lambda/T8032697.java
48795 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 803269726* @summary Issues with Lambda27*/2829import java.lang.invoke.LambdaMetafactory;30import java.lang.invoke.LambdaConversionException;31import java.lang.invoke.MethodHandle;32import java.lang.invoke.MethodHandles;33import java.lang.invoke.MethodType;3435import T8032697_anotherpkg.T8032697_A;3637public class T8032697 extends T8032697_A {3839interface I {40int m();41}4243interface IA {44int m(T8032697_A x);45}4647static MethodHandles.Lookup l;48static MethodHandle h;49private static MethodType mt(Class<?> k) { return MethodType.methodType(k); }50private static MethodType mt(Class<?> k, Class<?> k2) { return MethodType.methodType(k, k2); }51private static boolean mf(MethodType mti, MethodType mtf) {52try {53LambdaMetafactory.metafactory(l, "m", mti,mtf,h,mtf);54} catch(LambdaConversionException e) {55return true;56}57return false;58}5960public static void main(String[] args) throws Throwable {61l = MethodHandles.lookup();62h = l.findVirtual(T8032697_A.class, "f", mt(int.class));63if (mf(mt(I.class, T8032697.class), mt(int.class))) throw new AssertionError("Error: Should work");64if (mf(mt(IA.class), mt(int.class, T8032697.class))) throw new AssertionError("Error: Should work");65if (!mf(mt(I.class, T8032697_A.class), mt(int.class))) throw new AssertionError("Error: Should fail");66if (!mf(mt(IA.class), mt(int.class, T8032697_A.class))) throw new AssertionError("Error: Should fail");67}68}697071