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 */ 23 24/* 25 * @test 26 * @bug 8008077 8029721 27 * @summary new type annotation location: lambda expressions 28 * javac crash for annotated parameter type of lambda in a field 29 * @compile Lambda.java 30 * @author Werner Dietl 31 */ 32 33import java.lang.annotation.*; 34 35public class Lambda { 36 37 interface LambdaInt { 38 <S, T> void generic(S p1, T p2); 39 } 40 41 static class LambdaImpl implements LambdaInt { 42 <S, T> LambdaImpl(S p1, T p2) {} 43 public <S, T> void generic(S p1, T p2) {} 44 } 45 46 LambdaInt getMethodRefTA(LambdaImpl r) { 47 return r::<@TA Object, @TB Object>generic; 48 } 49 50 LambdaInt getConstructorRefTA() { 51 return LambdaImpl::<@TA Object, @TB Object>new; 52 } 53 54 interface LambdaInt2 { 55 void lambda(Object p1, Object p2); 56 } 57 58 LambdaInt2 getLambda() { 59 return (@TA Object x, @TB Object y) -> { @TA Object l = null; System.out.println("We have: " + (@TB Object) x); }; 60 } 61 62 java.util.function.IntUnaryOperator x = (@TA int y) -> 1; 63 64 static java.util.function.IntUnaryOperator xx = (@TA int y) -> 1; 65 66 java.util.function.IntUnaryOperator foo() { 67 return (@TA int y) -> 2; 68 } 69} 70 71@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 72@interface TA { } 73 74@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER}) 75@interface TB { } 76