Neg15.java revision 2868:816bd88d33a8
1147191Sjkoshy/* 2174215Sjkoshy * @test /nodynamiccopyright/ 3174215Sjkoshy * @bug 8062373 4147191Sjkoshy * 5147191Sjkoshy * @summary Test that javac complains when a <> inferred class contains a public method that does override a supertype method. 6174215Sjkoshy * @author sadayapalam 7174215Sjkoshy * @compile/fail/ref=Neg15.out Neg15.java -XDrawDiagnostics 8174215Sjkoshy * 9147191Sjkoshy */ 10147191Sjkoshy 11147191Sjkoshyclass Neg15 { 12147191Sjkoshy 13147191Sjkoshy interface Predicate<T> { 14147191Sjkoshy default boolean test(T t) { 15147191Sjkoshy System.out.println("Default method"); 16147191Sjkoshy return false; 17147191Sjkoshy } 18147191Sjkoshy } 19147191Sjkoshy 20147191Sjkoshy 21147191Sjkoshy static void someMethod(Predicate<? extends Number> p) { 22147191Sjkoshy if (!p.test(null)) 23147191Sjkoshy throw new Error("Blew it"); 24147191Sjkoshy } 25147191Sjkoshy 26147191Sjkoshy public static void main(String[] args) { 27147191Sjkoshy 28147191Sjkoshy someMethod(new Predicate<Integer>() { 29147191Sjkoshy public boolean test(Integer n) { 30147191Sjkoshy System.out.println("Override"); 31147191Sjkoshy return true; 32147191Sjkoshy } 33147191Sjkoshy boolean test(Integer n, int i) { 34147191Sjkoshy System.out.println("Override"); 35147191Sjkoshy return true; 36147191Sjkoshy } 37147191Sjkoshy protected boolean test(Integer n, int i, int j) { 38147191Sjkoshy System.out.println("Override"); 39147191Sjkoshy return true; 40147191Sjkoshy } 41147191Sjkoshy private boolean test(Integer n, int i, long j) { 42147191Sjkoshy System.out.println("Override"); 43147191Sjkoshy return true; 44147191Sjkoshy } 45147191Sjkoshy }); 46147191Sjkoshy 47147191Sjkoshy someMethod(new Predicate<>() { 48147191Sjkoshy public boolean test(Integer n) { // bad. 49147191Sjkoshy System.out.println("Override"); 50185363Sjkoshy return true; 51185363Sjkoshy } 52147191Sjkoshy boolean test(Integer n, int i) { // bad, package access. 53147191Sjkoshy System.out.println("Override"); 54147191Sjkoshy return true; 55147191Sjkoshy } 56147191Sjkoshy protected boolean test(Integer n, int i, int j) { // bad, protected access. 57147191Sjkoshy System.out.println("Override"); 58147191Sjkoshy return true; 59147191Sjkoshy } 60147191Sjkoshy private boolean test(Integer n, int i, long j) { // OK, private method. 61147191Sjkoshy System.out.println("Override"); 62147191Sjkoshy return true; 63147191Sjkoshy } 64147191Sjkoshy }); 65147191Sjkoshy } 66147191Sjkoshy} 67147191Sjkoshy