test/tools/javac/lambda/T8025290/ExplicitVSImplicitLambdaTest.java

Tue, 22 Oct 2013 13:54:49 +0100

author
vromero
date
Tue, 22 Oct 2013 13:54:49 +0100
changeset 2157
963c57175e40
parent 0
959103a6100f
permissions
-rw-r--r--

8025290: javac implicit versus explicit lambda compilation error
Reviewed-by: jjg, dlsmith

     1 /*
     2  * Copyright (c) 2013, 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  */
    24 /*
    25  * @test
    26  * @bug 8025290
    27  * @summary javac implicit versus explicit lambda compilation error
    28  * @compile ExplicitVSImplicitLambdaTest.java
    29  */
    31 import java.util.function.*;
    33 public class ExplicitVSImplicitLambdaTest {
    34     private void test()
    35     {
    36         /* in the explicit case "e" is inferred to String so we can use a String
    37          * only method.
    38          */
    39         MyComparator.mycomparing1((String e) -> e.concat(""));
    40         MyComparator.mycomparing2((String e) -> e.concat(""));
    41         MyComparator.mycomparing3((String e) -> e.concat(""));
    42         MyComparator.mycomparing4((String e) -> e.concat(""));
    44         /* in the implicit case "e" is inferred to Object so toString() is OK.
    45          */
    46         MyComparator.mycomparing1((e) -> e.toString());
    47         MyComparator.mycomparing2((e) -> e.toString());
    48         MyComparator.mycomparing3((e) -> e.toString());
    49         MyComparator.mycomparing4((e) -> e.toString());
    50     }
    51 }
    53 interface MyComparator<T> {
    54     public static <T, U extends Comparable<? super U>> MyComparator<T> mycomparing1(
    55             Function<? super T, ? extends U> keyExtractor) {
    56         return null;
    57     }
    59     public static <T, U extends Comparable<? super U>> MyComparator<T> mycomparing2(
    60             Function<? super T, ? super U> keyExtractor) {
    61         return null;
    62     }
    64     public static <T, U extends Comparable<? super U>> MyComparator<T> mycomparing3(
    65             Function<? extends T, ? extends U> keyExtractor) {
    66         return null;
    67     }
    69     public static <T, U extends Comparable<? super U>> MyComparator<T> mycomparing4(
    70             Function<? extends T, ? super U> keyExtractor) {
    71         return null;
    72     }
    73 }

mercurial