|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
|
|
Relates :
|
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)."
|