java-topology/test/langtools/tools/javac/generics/diamond/neg/Neg16.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

36 lines
1 KiB
Java

/*
* @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;
}
});
}
}