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();
  58         if (@A int.class != int.class) throw new Error();
  59         if (@A int.class != Integer.TYPE) throw new Error();
  60         if (@A int @B(0) [].class != int[].class) throw new Error();
  61 
  62         if (String[].class != @A String[].class) throw new Error();
  63         if (String[].class != String @A [].class) throw new Error();
  64         if (@A int[].class != int[].class) throw new Error();
  65         if (@A int @B(0) [].class != int[].class) throw new Error();
  66     }
  67 
  68     Object classLit1 = @A String @C [] @B(0) [].class;
  69     Object classLit2 = @A String @C []       [].class;
  70     Object classLit3 = @A String    [] @B(0) [].class;
  71     Object classLit4 =    String    [] @B(0) [].class;
  72     Object classLit5 =    String @C []       [].class;
  73     Object classLit6 =    String    []       [].class;
  74 }