1 | class Tester { void test(Object s) { System.out.println ("Object version"); } void test(Tester s) { System.out.println ("Tester version"); } void test(SubTester s) { System.out.println ("SubTester version"); } // Not compilable any more if you uncomment the line // since String and Tester are siblings // void test(String s) { System.out.println ("String version"); } public static void main (String args[]) { Tester c = new Tester (); // Ambiguous, the most specific one which fit will be call c.test (null); // SubTester version c.test (new Object()); // Object version } } class SubTester extends Tester{ } |
引用原文:
Quotation from JLS2
"The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error."
聯(lián)系客服