langtools/test/tools/javac/generics/diamond/neg/Neg16.java
author sadayapalam
Thu, 26 Nov 2015 17:38:15 +0530
changeset 34474 14deea5f86f1
parent 29776 984a79b71cfe
permissions -rw-r--r--
8078660: Misleading recommendation from diamond finder. Summary: javac should recommend diamond usage if that could lead to a change in program behavior. Reviewed-by: mcimadamore

/*
 * @test /nodynamiccopyright/
 * @bug 8062373
 * @summary Test that javac does not recommend a diamond site that would result in error.
 * @compile/ref=Neg16.out -Xlint:-options Neg16.java -XDrawDiagnostics -XDfind=diamond
 */

class Neg16 {

   interface Predicate<T> {
        default boolean test(T t) {
            System.out.println("Default method");
            return false;
        }
    }

    static void someMethod(Predicate<? extends Number> p) {
        if (!p.test(null))
            throw new Error("Blew it");
    }

    public static void main(String[] args) {
        someMethod(new Predicate<Integer>() { // cannot convert to diamond
            public boolean test(Integer n) {
                System.out.println("Override");
                return true;
            }
        });
        someMethod(new Predicate<Number>() { // can convert to diamond.
            public boolean test(Number n) {
                System.out.println("Override");
                return true;
            }
        });
    }
}