Summary: | [1.5][compiler] Bound mismatch when type casting | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | Yenchiu Ku <yenchiugu> |
Component: | Core | Assignee: | Philipe Mulet <philippe_mulet> |
Status: | VERIFIED WORKSFORME | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | Olivier_Thomann |
Version: | 3.3.1 | ||
Target Milestone: | 3.5 M5 | ||
Hardware: | PC | ||
OS: | Windows Server 2003 | ||
Whiteboard: |
Description
Yenchiu Ku
2008-03-03 21:47:33 EST
Was mis-categorized as APT - changed subcomponent to Core. javac doesn't perform bound checks on cast type !?
public class X<T extends Comparable<T>> {
T[] array;
public boolean equals(Object o) {
X<Comparable<T>> x;
if (array.length == ((X<Comparable<T>>) o).array.length) {
return true;
}
return false;
}
}
It only notices the first type inconsistency ("X<Comparable<T>> x;"), not the second one.
>javac X.java -d ..\bin -Xlint
X.java:5: type parameter java.lang.Comparable<T> is not within its bound
X<Comparable<T>> x;
^
X.java:6: warning: [unchecked] unchecked cast
found : java.lang.Object
required: X<java.lang.Comparable<T>>
if (array.length == ((X<Comparable<T>>) o).array.length) {
^
1 error
1 warning
Javac now reports 2 errors on scenario from comment 2 as expected in Java(TM) SE Runtime Environment (build 1.7.0-ea-b42). Added GenericTypeTest#test1442. Closing as worksforme since our behavior is the expected one (since 3.3.2) Verified for 3.5M5 using build I20090127-0100 and JRE 7.0 build 1.7.0-ea-b43 |