1 import static java.lang.annotation.ElementType.TYPE; 2 import static java.lang.annotation.ElementType.TYPE_PARAMETER; 3 import static java.lang.annotation.ElementType.TYPE_USE; 4 5 import java.lang.annotation.Retention; 6 import java.lang.annotation.RetentionPolicy; 7 import java.lang.annotation.Target; 8 9 /* 10 * Copyright (c) 2009 Oracle and/or its affiliates. All rights reserved. 11 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12 * 13 * This code is free software; you can redistribute it and/or modify it 14 * under the terms of the GNU General Public License version 2 only, as 15 * published by the Free Software Foundation. 16 * 17 * This code is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20 * version 2 for more details (a copy is included in the LICENSE file that 21 * accompanied this code). 22 * 23 * You should have received a copy of the GNU General Public License version 24 * 2 along with this work; if not, write to the Free Software Foundation, 25 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26 * 27 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28 * or visit www.oracle.com if you need additional information or have any 29 * questions. 30 */ 31 32 /* 33 * @test 34 * @summary Class literals are not type uses and cannot be annotated 35 * @author Werner Dietl 36 * @compile/fail/ref=DotClass.out -XDrawDiagnostics DotClass.java 37 */ 38 39 @Target({TYPE_USE, TYPE_PARAMETER, TYPE}) 40 @Retention(RetentionPolicy.RUNTIME) 41 @interface A {} 42 43 @interface B { int value(); } 44 45 class T0x1E { 46 void m0x1E() { 47 Class<Object> c = @A Object.class; 48 } 49 50 Class<?> c = @A String.class; 51 52 Class<? extends @A String> as = @A String.class; 53 } 54 55 class ClassLiterals { 56 public static void main(String[] args) { 57 if (String.class != @A String.class) throw new Error(); | 1 /* 2 * Copyright (c) 2009, 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 * @summary Class literals are not type uses and cannot be annotated 27 * @author Werner Dietl 28 * @compile/fail/ref=DotClass.out -XDrawDiagnostics DotClass.java 29 */ 30 31 import java.lang.annotation.Retention; 32 import java.lang.annotation.RetentionPolicy; 33 import java.lang.annotation.Target; 34 35 import static java.lang.annotation.ElementType.TYPE; 36 import static java.lang.annotation.ElementType.TYPE_PARAMETER; 37 import static java.lang.annotation.ElementType.TYPE_USE; 38 39 @Target({TYPE_USE, TYPE_PARAMETER, TYPE}) 40 @Retention(RetentionPolicy.RUNTIME) 41 @interface A {} 42 43 @interface B { int value(); } 44 45 class T0x1E { 46 void m0x1E() { 47 Class<Object> c = @A Object.class; 48 } 49 50 Class<?> c = @A String.class; 51 52 Class<? extends @A String> as = @A String.class; 53 } 54 55 class ClassLiterals { 56 public static void main(String[] args) { 57 if (String.class != @A String.class) throw new Error(); |