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.Arrays;
31import java.util.Comparator;
32import java.util.List;
33
34import static java.util.stream.Collectors.toList;
35
36public class MethodReferenceIntersection1 {
37
38    public static void main(String[] args) {
39        MethodReferenceIntersection1 main = new MethodReferenceIntersection1();
40        List<Info_MRI1> list = main.toInfoListError(Arrays.asList(new Base_MRI1()));
41        System.out.printf("result %d\n", list.size());
42    }
43
44    public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListError(List<H> list) {
45        Comparator<B_MRI1> byNameComparator =
46                    (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
47        return list.stream().sorted(byNameComparator).map(Info_MRI1::new).collect(toList());
48    }
49
50    public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListWorks(List<H> list) {
51        Comparator<B_MRI1> byNameComparator =
52                    (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
53        return list.stream().sorted(byNameComparator).map(s -> new Info_MRI1(s)).collect(toList());
54    }
55}
56
57interface B_MRI1 {
58    public String getB();
59}
60
61interface A_MRI1 {
62    public long getA();
63}
64
65class Info_MRI1 {
66    private final long a;
67    private final String b;
68
69    <H extends A_MRI1 & B_MRI1> Info_MRI1(H h) {
70        a = h.getA();
71        b = h.getB();
72    }
73}
74
75class Base_MRI1 implements A_MRI1, B_MRI1 {
76
77    @Override
78    public long getA() {
79        return 7L;
80    }
81
82    @Override
83    public String getB() {
84        return "hello";
85    }
86}
87