1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
/*
* @test /nodynamiccopyright/
* @bug 8062373 8151018
*
* @summary Test that javac complains when a <> inferred class contains a public method that does override a supertype method.
* @author sadayapalam
* @compile/fail/ref=Neg15.out Neg15.java -XDrawDiagnostics
*
*/
class Neg15 {
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>() {
public boolean test(Integer n) {
System.out.println("Override");
return true;
}
boolean test(Integer n, int i) {
System.out.println("Override");
return true;
}
protected boolean test(Integer n, int i, int j) {
System.out.println("Override");
return true;
}
private boolean test(Integer n, int i, long j) {
System.out.println("Override");
return true;
}
});
someMethod(new Predicate<>() {
public boolean test(Integer n) { // bad.
System.out.println("Override");
return true;
}
boolean test(Integer n, int i) { // bad, package access.
System.out.println("Override");
return true;
}
protected boolean test(Integer n, int i, int j) { // bad, protected access.
System.out.println("Override");
return true;
}
private boolean test(Integer n, int i, long j) { // OK, private method.
System.out.println("Override");
return true;
}
});
}
}
|