-
Bug
-
Resolution: Fixed
-
P5
-
6
-
None
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?
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?
- relates to
-
JDK-7018313 5.1.9: Unchecked conversion during assignment/method invocation is too lax
- Open
-
JDK-6508599 5.1.9: No unchecked conversion for array types
- Closed
-
JDK-6558557 Overhaul specification of unchecked casts
- Closed