langtools/test/tools/javac/annotations/typeAnnotations/failures/LintCast.java
changeset 15385 ee1eebe7e210
equal deleted inserted replaced
15384:5a8d00abf076 15385:ee1eebe7e210
       
     1 import java.lang.annotation.*;
       
     2 import java.util.List;
       
     3 
       
     4 /*
       
     5  * @test /nodynamiccopyright/
       
     6  * @bug 6843077 8006775
       
     7  * @summary test that compiler doesn't warn about annotated redundant casts
       
     8  * @author Mahmood Ali
       
     9  * @author Werner Dietl
       
    10  * @compile/ref=LintCast.out -Xlint:cast -XDrawDiagnostics LintCast.java
       
    11  */
       
    12 class LintCast {
       
    13     void unparameterized() {
       
    14         String s = "m";
       
    15         String s1 = (String)s;
       
    16         String s2 = (@A String)s;
       
    17     }
       
    18 
       
    19     void parameterized() {
       
    20         List<String> l = null;
       
    21         List<String> l1 = (List<String>)l;
       
    22         List<String> l2 = (List<@A String>)l;
       
    23     }
       
    24 
       
    25     void array() {
       
    26         int @A [] a = null;
       
    27         int[] a1 = (int[])a;
       
    28         int[] a2 = (int @A [])a;
       
    29     }
       
    30 
       
    31     void sameAnnotations() {
       
    32         @A String annotated = null;
       
    33         String unannotated = null;
       
    34 
       
    35         // compiler ignore annotated casts even if redundant
       
    36         @A String anno1 = (@A String)annotated;
       
    37 
       
    38         // warn if redundant without an annotation
       
    39         String anno2 = (String)annotated;
       
    40         String unanno2 = (String)unannotated;
       
    41     }
       
    42 
       
    43     void more() {
       
    44         Object @A [] a = null;
       
    45         Object[] a1 = (Object[])a;
       
    46         Object[] a2 = (Object @A [])a;
       
    47 
       
    48         @A List<String> l3 = null;
       
    49         List<String> l4 = (List<String>)l3;
       
    50         List<String> l5 = (@A List<String>)l3;
       
    51 
       
    52         List<@A String> l6 = null;
       
    53         List<String> l7 = (List<String>)l6;
       
    54         List<String> l8 = (List<@A String>)l6;
       
    55 
       
    56         @A Object o = null;
       
    57         Object o1 = (Object)o;
       
    58         Object o2 = (@A Object)o;
       
    59 
       
    60         Outer. @A Inner oi = null;
       
    61         Outer.Inner oi1 = (Outer.Inner)oi;
       
    62         Outer.Inner oi2 = (Outer. @A Inner)oi;
       
    63     }
       
    64 
       
    65     class Outer { class Inner {} }
       
    66 }
       
    67 
       
    68 @Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
       
    69 @interface A { }