test/tools/javac/lambda/MethodReference31.java

changeset 0
959103a6100f
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/lambda/MethodReference31.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,217 @@
     1.4 +/*
     1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug 8003280
    1.30 + * @summary Add lambda tests
    1.31 + *  check that boxing of return-type works as expected
    1.32 + */
    1.33 +
    1.34 +public class MethodReference31 {
    1.35 +
    1.36 +    static class Success extends RuntimeException { }
    1.37 +
    1.38 +    static int assertionCount = 0;
    1.39 +
    1.40 +    static void assertTrue(boolean cond) {
    1.41 +        assertionCount++;
    1.42 +        if (!cond)
    1.43 +            throw new AssertionError();
    1.44 +    }
    1.45 +
    1.46 +    interface SAM<X> {
    1.47 +        X m();
    1.48 +    }
    1.49 +
    1.50 +    interface SAM_byte {
    1.51 +        byte m();
    1.52 +    }
    1.53 +
    1.54 +    interface SAM_short {
    1.55 +        short m();
    1.56 +    }
    1.57 +
    1.58 +    interface SAM_int {
    1.59 +        int m();
    1.60 +    }
    1.61 +
    1.62 +    interface SAM_long {
    1.63 +        long m();
    1.64 +    }
    1.65 +
    1.66 +    interface SAM_float {
    1.67 +        float m();
    1.68 +    }
    1.69 +
    1.70 +    interface SAM_double {
    1.71 +        double m();
    1.72 +    }
    1.73 +
    1.74 +    static <Z> Z test() {
    1.75 +        assertTrue(true);
    1.76 +        throw new Success();
    1.77 +    }
    1.78 +
    1.79 +    static byte test_byte() {
    1.80 +        assertTrue(true);
    1.81 +        return 0;
    1.82 +    }
    1.83 +
    1.84 +    static short test_short() {
    1.85 +        assertTrue(true);
    1.86 +        return 0;
    1.87 +    }
    1.88 +
    1.89 +    static int test_int() {
    1.90 +        assertTrue(true);
    1.91 +        return 0;
    1.92 +    }
    1.93 +
    1.94 +    static long test_long() {
    1.95 +        assertTrue(true);
    1.96 +        return 0;
    1.97 +    }
    1.98 +
    1.99 +    static float test_float() {
   1.100 +        assertTrue(true);
   1.101 +        return 0;
   1.102 +    }
   1.103 +
   1.104 +    static double test_double() {
   1.105 +        assertTrue(true);
   1.106 +        return 0;
   1.107 +    }
   1.108 +
   1.109 +    static void testByte() {
   1.110 +        SAM<Byte> s1 = MethodReference31::test_byte;
   1.111 +        s1.m();
   1.112 +        SAM_byte s2 = MethodReference31::test_byte;
   1.113 +        s2.m();
   1.114 +        SAM<Byte> s3 = MethodReference31::<Byte>test;
   1.115 +        try {
   1.116 +            s3.m();
   1.117 +        }
   1.118 +        catch (RuntimeException ex) { }
   1.119 +        SAM_byte s4 = MethodReference31::<Byte>test;
   1.120 +        try {
   1.121 +            s4.m();
   1.122 +        }
   1.123 +        catch (RuntimeException ex) { }
   1.124 +    }
   1.125 +
   1.126 +    static void testShort() {
   1.127 +        SAM<Short> s1 = MethodReference31::test_short;
   1.128 +        s1.m();
   1.129 +        SAM_short s2 = MethodReference31::test_short;
   1.130 +        s2.m();
   1.131 +        SAM<Short> s3 = MethodReference31::<Short>test;
   1.132 +        try {
   1.133 +            s3.m();
   1.134 +        }
   1.135 +        catch (RuntimeException ex) { }
   1.136 +        SAM_short s4 = MethodReference31::<Short>test;
   1.137 +        try {
   1.138 +            s4.m();
   1.139 +        }
   1.140 +        catch (RuntimeException ex) { }
   1.141 +    }
   1.142 +
   1.143 +    static void testInteger() {
   1.144 +        SAM<Integer> s1 = MethodReference31::test_int;
   1.145 +        s1.m();
   1.146 +        SAM_int s2 = MethodReference31::test_int;
   1.147 +        s2.m();
   1.148 +        SAM<Integer> s3 = MethodReference31::<Integer>test;
   1.149 +        try {
   1.150 +            s3.m();
   1.151 +        }
   1.152 +        catch (RuntimeException ex) { }
   1.153 +        SAM_int s4 = MethodReference31::<Integer>test;
   1.154 +        try {
   1.155 +            s4.m();
   1.156 +        }
   1.157 +        catch (RuntimeException ex) { }
   1.158 +    }
   1.159 +
   1.160 +    static void testLong() {
   1.161 +        SAM<Long> s1 = MethodReference31::test_long;
   1.162 +        s1.m();
   1.163 +        SAM_long s2 = MethodReference31::test_long;
   1.164 +        s2.m();
   1.165 +        SAM<Long> s3 = MethodReference31::<Long>test;
   1.166 +        try {
   1.167 +            s3.m();
   1.168 +        }
   1.169 +        catch (RuntimeException ex) { }
   1.170 +        SAM_long s4 = MethodReference31::<Long>test;
   1.171 +        try {
   1.172 +            s4.m();
   1.173 +        }
   1.174 +        catch (RuntimeException ex) { }
   1.175 +    }
   1.176 +
   1.177 +    static void testFloat() {
   1.178 +        SAM<Float> s1 = MethodReference31::test_float;
   1.179 +        s1.m();
   1.180 +        SAM_float s2 = MethodReference31::test_float;
   1.181 +        s2.m();
   1.182 +        SAM<Float> s3 = MethodReference31::<Float>test;
   1.183 +        try {
   1.184 +            s3.m();
   1.185 +        }
   1.186 +        catch (RuntimeException ex) { }
   1.187 +        SAM_float s4 = MethodReference31::<Float>test;
   1.188 +        try {
   1.189 +            s4.m();
   1.190 +        }
   1.191 +        catch (RuntimeException ex) { }
   1.192 +    }
   1.193 +
   1.194 +    static void testDouble() {
   1.195 +        SAM<Double> s1 = MethodReference31::test_double;
   1.196 +        s1.m();
   1.197 +        SAM_double s2 = MethodReference31::test_double;
   1.198 +        s2.m();
   1.199 +        SAM<Double> s3 = MethodReference31::<Double>test;
   1.200 +        try {
   1.201 +            s3.m();
   1.202 +        }
   1.203 +        catch (RuntimeException ex) { }
   1.204 +        SAM_double s4 = MethodReference31::<Double>test;
   1.205 +        try {
   1.206 +            s4.m();
   1.207 +        }
   1.208 +        catch (RuntimeException ex) { }
   1.209 +    }
   1.210 +
   1.211 +    public static void main(String[] args) {
   1.212 +        testByte();
   1.213 +        testShort();
   1.214 +        testInteger();
   1.215 +        testLong();
   1.216 +        testFloat();
   1.217 +        testDouble();
   1.218 +        assertTrue(assertionCount == 24);
   1.219 +    }
   1.220 +}

mercurial