langtools/test/tools/javac/lambda/methodReferenceExecution/MethodReferenceIntersection1.java
changeset 27855 7afea3897f9b
child 32337 c9d3ab9f601c
equal deleted inserted replaced
27854:22b4bfc4e22f 27855:7afea3897f9b
       
     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.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 /**
       
    27  * @test
       
    28  * @bug 8058112
       
    29  * @summary Invalid BootstrapMethod for constructor/method reference
       
    30  */
       
    31 
       
    32 import java.util.Arrays;
       
    33 import java.util.Comparator;
       
    34 import java.util.List;
       
    35 
       
    36 import static java.util.stream.Collectors.toList;
       
    37 
       
    38 public class MethodReferenceIntersection1 {
       
    39 
       
    40     public static void main(String[] args) {
       
    41         MethodReferenceIntersection1 main = new MethodReferenceIntersection1();
       
    42         List<Info_MRI1> list = main.toInfoListError(Arrays.asList(new Base_MRI1()));
       
    43         System.out.printf("result %d\n", list.size());
       
    44     }
       
    45 
       
    46     public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListError(List<H> list) {
       
    47         Comparator<B_MRI1> byNameComparator =
       
    48                     (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
       
    49         return list.stream().sorted(byNameComparator).map(Info_MRI1::new).collect(toList());
       
    50     }
       
    51 
       
    52     public <H extends B_MRI1 & A_MRI1> List<Info_MRI1> toInfoListWorks(List<H> list) {
       
    53         Comparator<B_MRI1> byNameComparator =
       
    54                     (B_MRI1 b1, B_MRI1 b2) -> b1.getB().compareToIgnoreCase(b2.getB());
       
    55         return list.stream().sorted(byNameComparator).map(s -> new Info_MRI1(s)).collect(toList());
       
    56     }
       
    57 }
       
    58 
       
    59 interface B_MRI1 {
       
    60     public String getB();
       
    61 }
       
    62 
       
    63 interface A_MRI1 {
       
    64     public long getA();
       
    65 }
       
    66 
       
    67 class Info_MRI1 {
       
    68     private final long a;
       
    69     private final String b;
       
    70 
       
    71     <H extends A_MRI1 & B_MRI1> Info_MRI1(H h) {
       
    72         a = h.getA();
       
    73         b = h.getB();
       
    74     }
       
    75 }
       
    76 
       
    77 class Base_MRI1 implements A_MRI1, B_MRI1 {
       
    78 
       
    79     @Override
       
    80     public long getA() {
       
    81         return 7L;
       
    82     }
       
    83 
       
    84     @Override
       
    85     public String getB() {
       
    86         return "hello";
       
    87     }
       
    88 }