-
Bug
-
Resolution: Fixed
-
P4
-
5.0
-
rc
-
generic
-
generic
-
Verified
http://forum.java.sun.com/thread.jspa?forumID=316&threadID=634688
https://bugs.eclipse.org/bugs/show_bug.cgi?id=99107
public final class A<B> {
void doit() {
Class<A> clazz1 = (Class<A>) this.getClass();
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
clazz2.getName();
}
}
Sun's javac (1.5.0_03) gives an error:
A.java:5: inconvertible types
found : java.lang.Class<A>
required: java.lang.Class<A<B>>
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
^
------- Additional Comment #1 From Philippe Mulet 2005-06-09 06:11 [reply] -------
According to the spec, cast conversion is allowed since the types are
not probably distinct.
I thus believe this is a bug in javac.
Another example where non-provably distinct types are treated as distinct:
import java.io.*;
import java.util.*;
public class X {
public static void main(String[] args) {
LinkedList<String> linkedList= new LinkedList<String>();
List<? extends Serializable> a = linkedList;
List<Runtime> d = (LinkedList<Runtime>) a; // inconvertible! ??
}
}
PPM says: "Javac thinks it is inconvertible, I think it should only be an unchecked cast.
Basically List<capture-of-? extends Serializable> is not provably distinct from List<Runtime>
this comes from the fact when recursing into the algorithm an implementation of Serializable may well subclass Runtime (hence you cannot complain for sure)."
https://bugs.eclipse.org/bugs/show_bug.cgi?id=99107
public final class A<B> {
void doit() {
Class<A> clazz1 = (Class<A>) this.getClass();
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
clazz2.getName();
}
}
Sun's javac (1.5.0_03) gives an error:
A.java:5: inconvertible types
found : java.lang.Class<A>
required: java.lang.Class<A<B>>
Class<A<B>> clazz2 = (Class<A<B>>) clazz1;
^
------- Additional Comment #1 From Philippe Mulet 2005-06-09 06:11 [reply] -------
According to the spec, cast conversion is allowed since the types are
not probably distinct.
I thus believe this is a bug in javac.
Another example where non-provably distinct types are treated as distinct:
import java.io.*;
import java.util.*;
public class X {
public static void main(String[] args) {
LinkedList<String> linkedList= new LinkedList<String>();
List<? extends Serializable> a = linkedList;
List<Runtime> d = (LinkedList<Runtime>) a; // inconvertible! ??
}
}
PPM says: "Javac thinks it is inconvertible, I think it should only be an unchecked cast.
Basically List<capture-of-? extends Serializable> is not provably distinct from List<Runtime>
this comes from the fact when recursing into the algorithm an implementation of Serializable may well subclass Runtime (hence you cannot complain for sure)."
- relates to
-
JDK-7005095 Cast: compile reject sensible cast from final class to interface
- Closed
-
JDK-6557182 Unchecked warning *and* inconvertible types
- Closed
-
JDK-7005140 Cast: write new regression test checking all combinations
- Open
-
JDK-6790039 overhaul cast-conversion (umbrella)
- Closed
-
JDK-6270087 Javac rejects legal cast
- Closed