J
John C. Bollinger
Consider this method:
List<String> createStringList(final String[] array) {
return new AbstractList<String>() {
public int size() {
return array.length;
}
public String get(int i) { // Note the return type
return array;
}
};
}
The code compiles without error or warning with Sun's 1.5.0 compiler,
but Eclipse 3.1 M4 complains (a warning) about an unchecked type
conversion being required to convert String to the return type of the
superclass' method (E). Is M4's support for generics just lacking in
this regard? I'm having trouble seeing how there is any unsafe cast
required, but on the other hand it also seems that I'm leveraging the
new covariant return type feature to get what I want at all, and that
doesn't feel right.
List<String> createStringList(final String[] array) {
return new AbstractList<String>() {
public int size() {
return array.length;
}
public String get(int i) { // Note the return type
return array;
}
};
}
The code compiles without error or warning with Sun's 1.5.0 compiler,
but Eclipse 3.1 M4 complains (a warning) about an unchecked type
conversion being required to convert String to the return type of the
superclass' method (E). Is M4's support for generics just lacking in
this regard? I'm having trouble seeing how there is any unsafe cast
required, but on the other hand it also seems that I'm leveraging the
new covariant return type feature to get what I want at all, and that
doesn't feel right.