Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
According to 5.2 (assignment conversions) the second shouldn't be allowed, as it would be a widening reference conversion followed by an unboxing conversion, which isn't among the allowed conversions. However, I believe that is a bug in the JLS. (One could infer that T must be Integer, as Integer is final, but the type rules don't take advantage of final). A widening reference conversion followed by unboxing isn't listed among the conversions allowed in the corrections in http://java.sun.com/docs/books/jls/jls-proposed-changes.html . Perhaps Alex will get it fixed in the next round. -Neal On 5/1/07, ... wrote: I'm curious about this case: class A<T extends Integer> { T x = (T)37; // javac gives error int i = (int)x; // javac gives no error } javac gives an error on the first case but not the second. The JLS says in 5.5: A value of a primitive type can be cast to a reference type by boxing conversion (��5.1.7). A value of a reference type can be cast to a primitive type by unboxing conversion (��5.1.8). It's not clear whether that means one of those conversions plus something else. If I read it as only boxing or unboxing, the error on the first case makes sense. But then I would also expect an error on the second case. Which way is right? Is there a javac bug here on one of these cases?
|