MethodReferenceIntersection2.java revision 3014:a3dd196e5341
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 8058112 27 * @summary Invalid BootstrapMethod for constructor/method reference 28 */ 29 30import java.util.function.Function; 31 32public class MethodReferenceIntersection2 { 33 34 interface B { } 35 36 interface A { } 37 38 static class C implements A, B { } 39 40 static class Info { 41 <H extends A & B> Info(H h) { } 42 43 static <H extends A & B> Info info(H h) { 44 return new Info(h); 45 } 46 } 47 48 public static void main(String[] args) { 49 test(); 50 } 51 52 // Note the switch in order compared to that on Info 53 static <H extends B & A> void test() { 54 Function<H, Info> f1L = _h -> new Info(_h); 55 Function<H, Info> f1 = Info::new; 56 Function<H, Info> f2L = _h -> Info.info(_h); 57 Function<H, Info> f2 = Info::info; 58 H c = (H) new C(); 59 if(f1.apply(c) instanceof Info && 60 f2.apply(c) instanceof Info) { 61 System.out.println("Passes."); 62 } else { 63 throw new AssertionError(); 64 } 65 } 66} 67