Relates :
|
|
Relates :
|
|
Relates :
|
From: J. Stephen Adamczyk <###@###.###> Date: Aug 11, 2006 12:09 PM Subject: Unchecked conversion To: Neal Gafter < ###@###.###> Cc: "John H. Spicer" <###@###.###> The JLS says several times (e.g., 5.3) that when an unchecked conversion is considered "It is a compile-time error if the chain of conversions contains two parameterized types that are not in the subtype relationship". The example of such an invalid chain given in 5.2 is Integer, Comparable<Integer>, Comparable, Comparable<String> I *think* that the JLS really intends is "such an invalid sequence causes the unchecked conversion not to be allowed" rather than what it seems to say, which is "such an invalid sequence causes an error if the unchecked conversion is used". Here's a test case: public class Test { static void g(Comparable<String> x) { System.out.println( "one" ); } static void g(int x) { System.out.println( "two" ); } public static void main( String[] args ) { Integer i = 1; g(i); } } This compiles without error and prints "two", thus suggesting that the disallowed unchecked conversion is simply ignored, rather than selected and then flagged as an error. I don't think that "most specific" distinguishes between the two candidates. If it does, then maybe I'm drawing the wrong conclusion. Do I have this right?
|