Originally posted by Gopal Shah:
No the second code doesn't compile becoz
-> Abc can be converted into Xyz but long cannot be converted into int
-> int can be converted into long but Xyz cannot be converted into Abc
java version "1.4.2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)
The parameter 5 is an int which can only be assigned to the parameter l
SCJP2. Please Indent your code using UBB Code
Originally posted by Marlene Miller:
Here is a bug report about ambiguous methods and interfaces.
http://developer.java.sun.com/developer/bugParade/bugs/4279316.html
Originally posted by Marlene Miller:
What confuses me is that the 1.4.2 fix is inconsistent with the JLS.
JLS 15.12.2.2
If more than one method declaration is both accessible and applicable to a method invocation, it is necessary to choose one to provide the descriptor for the run-time method dispatch. The Java programming language uses the rule that the most specific method is chosen.
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.
The precise definition is as follows. Let m be a name and suppose that there are two member methods named m, each having n parameters. Suppose that the types of the parameters of one member method are T1, . . . , Tn; suppose moreover that the types of the parameters of the other method are U1, . . . , Un. Then the first member method is more specific than other if and only if Tj can be converted to Uj by method invocation conversion, for all j from 1 to n. A method is strictly more specific than another if and only if it is both more specific and the signatures of the two methods are not identical.
A method is said to be maximally specific for a method invocation if it is applicable and accessible and there is no other applicable and accessible method that is strictly more specific.
If there is exactly one maximally specific method, then it is in fact the most specific method; it is necessarily more specific than any other method that is applicable and accessible. It is then subjected to some further compile-time checks as described in �15.12.3.
It is possible that no method is the most specific, because there are two or more maximally specific methods. In this case:
If all the maximally specific methods have the same signature, then:
* If one of the maximally specific methods is not declared abstract, it is the most specific method.
* Otherwise, all the maximally specific methods are necessarily declared abstract. The most specific method is chosen arbitrarily among the maximally specific methods. However, the most specific method is considered to throw a checked exception if and only if that exception is declared in the throws clauses of each of the maximally specific methods.
* Otherwise, we say that the method invocation is ambiguous, and a compile-time error occurs.
SCJP2. Please Indent your code using UBB Code
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |