001    import java.util.*;
002    
003    /**
004     * This class illustrates an incorrect use of the @NonNull type annotation.
005     * The class doesn't do anything -- it is merely meant to be compiled.
006     * Compilation will produce warning messages.
007     * <p>
008    
009     * Also see {@link NullnessExample}, an example of correct use
010     * of the @NonNull type annotation.  See the Nullness checker documentation
011     * for larger examples of annotated code.
012     **/
013    public class NullnessExampleWithWarnings {
014    
015      public void example() {
016    
017        // This type annotation is redundant -- the Nullness Checker will
018        // infer it, but it is written here in the example for emhpasis.
019        // In general, you do not have to annotate local variables.
020        /*@NonNull*/ String foo = "foo";
021        String bar = null;
022    
023        foo = bar;
024        bar = foo;
025    
026      }
027    
028      public /*@NonNull*/ String exampleGenerics() {
029    
030        List</*@NonNull*/ String> foo = new LinkedList</*@NonNull*/ String>();
031        List<String> bar = foo;
032    
033        String quux = null;
034        foo.add(quux);
035        foo.add("quux");
036        /*@NonNull*/ String baz = foo.get(0);
037        return baz;
038    
039      }
040    
041    }