langtools/test/tools/javac/typeAnnotations/failures/LintCast.java
changeset 7382 e1ed8c9e12e5
parent 7381 5d924959cd81
parent 7140 4951967a61b4
child 7383 cbd66f8db06b
equal deleted inserted replaced
7381:5d924959cd81 7382:e1ed8c9e12e5
     1 import java.util.List;
       
     2 
       
     3 /*
       
     4  * @test /nodynamiccopyright/
       
     5  * @bug 6843077
       
     6  * @summary test that compiler doesn't warn about annotated redundant casts
       
     7  * @author Mahmood Ali
       
     8  * @compile/ref=LintCast.out -Xlint:cast -XDrawDiagnostics -source 1.7 LintCast.java
       
     9  */
       
    10 class LintCast {
       
    11     void unparameterized() {
       
    12         String s = "m";
       
    13         String s1 = (String)s;
       
    14         String s2 = (@A String)s;
       
    15     }
       
    16 
       
    17     void parameterized() {
       
    18         List<String> l = null;
       
    19         List<String> l1 = (List<String>)l;
       
    20         List<String> l2 = (List<@A String>)l;
       
    21     }
       
    22 
       
    23     void array() {
       
    24         int @A [] a = null;
       
    25         int[] a1 = (int[])a;
       
    26         int[] a2 = (int @A [])a;
       
    27     }
       
    28 
       
    29     void sameAnnotations() {
       
    30         @A String annotated = null;
       
    31         String unannotated = null;
       
    32 
       
    33         // compiler ignore annotated casts even if redundant
       
    34         @A String anno1 = (@A String)annotated;
       
    35 
       
    36         // warn if redundant without an annotation
       
    37         String anno2 = (String)annotated;
       
    38         String unanno2 = (String)unannotated;
       
    39     }
       
    40 }
       
    41 
       
    42 @interface A { }