MethodReference31.java revision 1414:01c9d4161882
1239691Srwatson/*
2239691Srwatson * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
3239691Srwatson * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4239691Srwatson *
5239691Srwatson * This code is free software; you can redistribute it and/or modify it
6239691Srwatson * under the terms of the GNU General Public License version 2 only, as
7239691Srwatson * published by the Free Software Foundation.
8239691Srwatson *
9239691Srwatson * This code is distributed in the hope that it will be useful, but WITHOUT
10239691Srwatson * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11239691Srwatson * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12239691Srwatson * version 2 for more details (a copy is included in the LICENSE file that
13239691Srwatson * accompanied this code).
14239691Srwatson *
15239691Srwatson * You should have received a copy of the GNU General Public License version
16239691Srwatson * 2 along with this work; if not, write to the Free Software Foundation,
17239691Srwatson * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18239691Srwatson *
19239691Srwatson * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20239691Srwatson * or visit www.oracle.com if you need additional information or have any
21239691Srwatson * questions.
22239691Srwatson */
23239691Srwatson
24239691Srwatson/*
25239691Srwatson * @test
26239691Srwatson * @bug 8003280
27239691Srwatson * @summary Add lambda tests
28239691Srwatson *  check that boxing of return-type works as expected
29239691Srwatson */
30239691Srwatson
31239691Srwatsonpublic class MethodReference31 {
32239691Srwatson
33239691Srwatson    static class Success extends RuntimeException { }
34239691Srwatson
35239691Srwatson    static int assertionCount = 0;
36239691Srwatson
37239691Srwatson    static void assertTrue(boolean cond) {
38239691Srwatson        assertionCount++;
39239691Srwatson        if (!cond)
40239691Srwatson            throw new AssertionError();
41239691Srwatson    }
42239691Srwatson
43239691Srwatson    interface SAM<X> {
44239691Srwatson        X m();
45239691Srwatson    }
46239691Srwatson
47239691Srwatson    interface SAM_byte {
48239691Srwatson        byte m();
49239691Srwatson    }
50239691Srwatson
51239691Srwatson    interface SAM_short {
52239691Srwatson        short m();
53239691Srwatson    }
54239691Srwatson
55239691Srwatson    interface SAM_int {
56239691Srwatson        int m();
57239691Srwatson    }
58239691Srwatson
59239691Srwatson    interface SAM_long {
60239691Srwatson        long m();
61239691Srwatson    }
62239691Srwatson
63239691Srwatson    interface SAM_float {
64239691Srwatson        float m();
65239691Srwatson    }
66239691Srwatson
67239691Srwatson    interface SAM_double {
68239691Srwatson        double m();
69239691Srwatson    }
70239691Srwatson
71239691Srwatson    static <Z> Z test() {
72239691Srwatson        assertTrue(true);
73239691Srwatson        throw new Success();
74239691Srwatson    }
75239691Srwatson
76239691Srwatson    static byte test_byte() {
77239691Srwatson        assertTrue(true);
78239691Srwatson        return 0;
79239691Srwatson    }
80239691Srwatson
81239691Srwatson    static short test_short() {
82239691Srwatson        assertTrue(true);
83239691Srwatson        return 0;
84239691Srwatson    }
85239691Srwatson
86239691Srwatson    static int test_int() {
87239691Srwatson        assertTrue(true);
88239691Srwatson        return 0;
89239691Srwatson    }
90239691Srwatson
91239691Srwatson    static long test_long() {
92239691Srwatson        assertTrue(true);
93239691Srwatson        return 0;
94239691Srwatson    }
95239691Srwatson
96239691Srwatson    static float test_float() {
97239691Srwatson        assertTrue(true);
98239691Srwatson        return 0;
99239691Srwatson    }
100239691Srwatson
101239691Srwatson    static double test_double() {
102239691Srwatson        assertTrue(true);
103239691Srwatson        return 0;
104239691Srwatson    }
105239691Srwatson
106239691Srwatson    static void testByte() {
107239691Srwatson        SAM<Byte> s1 = MethodReference31::test_byte;
108239691Srwatson        s1.m();
109239691Srwatson        SAM_byte s2 = MethodReference31::test_byte;
110239691Srwatson        s2.m();
111239691Srwatson        SAM<Byte> s3 = MethodReference31::<Byte>test;
112239691Srwatson        try {
113239691Srwatson            s3.m();
114239691Srwatson        }
115239691Srwatson        catch (RuntimeException ex) { }
116239691Srwatson        SAM_byte s4 = MethodReference31::<Byte>test;
117239691Srwatson        try {
118239691Srwatson            s4.m();
119239691Srwatson        }
120239691Srwatson        catch (RuntimeException ex) { }
121239691Srwatson    }
122239691Srwatson
123239691Srwatson    static void testShort() {
124239691Srwatson        SAM<Short> s1 = MethodReference31::test_short;
125239691Srwatson        s1.m();
126239691Srwatson        SAM_short s2 = MethodReference31::test_short;
127239691Srwatson        s2.m();
128239691Srwatson        SAM<Short> s3 = MethodReference31::<Short>test;
129239691Srwatson        try {
130239691Srwatson            s3.m();
131239691Srwatson        }
132        catch (RuntimeException ex) { }
133        SAM_short s4 = MethodReference31::<Short>test;
134        try {
135            s4.m();
136        }
137        catch (RuntimeException ex) { }
138    }
139
140    static void testInteger() {
141        SAM<Integer> s1 = MethodReference31::test_int;
142        s1.m();
143        SAM_int s2 = MethodReference31::test_int;
144        s2.m();
145        SAM<Integer> s3 = MethodReference31::<Integer>test;
146        try {
147            s3.m();
148        }
149        catch (RuntimeException ex) { }
150        SAM_int s4 = MethodReference31::<Integer>test;
151        try {
152            s4.m();
153        }
154        catch (RuntimeException ex) { }
155    }
156
157    static void testLong() {
158        SAM<Long> s1 = MethodReference31::test_long;
159        s1.m();
160        SAM_long s2 = MethodReference31::test_long;
161        s2.m();
162        SAM<Long> s3 = MethodReference31::<Long>test;
163        try {
164            s3.m();
165        }
166        catch (RuntimeException ex) { }
167        SAM_long s4 = MethodReference31::<Long>test;
168        try {
169            s4.m();
170        }
171        catch (RuntimeException ex) { }
172    }
173
174    static void testFloat() {
175        SAM<Float> s1 = MethodReference31::test_float;
176        s1.m();
177        SAM_float s2 = MethodReference31::test_float;
178        s2.m();
179        SAM<Float> s3 = MethodReference31::<Float>test;
180        try {
181            s3.m();
182        }
183        catch (RuntimeException ex) { }
184        SAM_float s4 = MethodReference31::<Float>test;
185        try {
186            s4.m();
187        }
188        catch (RuntimeException ex) { }
189    }
190
191    static void testDouble() {
192        SAM<Double> s1 = MethodReference31::test_double;
193        s1.m();
194        SAM_double s2 = MethodReference31::test_double;
195        s2.m();
196        SAM<Double> s3 = MethodReference31::<Double>test;
197        try {
198            s3.m();
199        }
200        catch (RuntimeException ex) { }
201        SAM_double s4 = MethodReference31::<Double>test;
202        try {
203            s4.m();
204        }
205        catch (RuntimeException ex) { }
206    }
207
208    public static void main(String[] args) {
209        testByte();
210        testShort();
211        testInteger();
212        testLong();
213        testFloat();
214        testDouble();
215        assertTrue(assertionCount == 24);
216    }
217}
218