'java.lang.String[]' incompatible with 'E'
I have an iterator in a while loop, in which everytimes I retrieve a string array. The code looks like this:
...
String[] refs = (String[])it.next();
...
I use jdeveloper 10.1.3 with jdk 1.5 and the code was ok. When I use jdeveloper 11.tp with jdk 1.6 it shows warnings like:
Type 'java.lang.String[]' incompatible with 'E' or sometimes with 'V'.
What does it mean and how do I get around this?
[444 byte] By [
mathos2a] at [2007-11-27 5:54:42]

Aha ..., I see, it has to do with generics. So I have to declare it correctly like this:
Iterator<String[]> it = collection.iterator();
while(it.hasNext())
{
String[] refs = it.next();
.....
}
and it works.
Thanks for your tip, Hippolyte.
That's just a warning. Your code will still compile. You can ignore it, or you can learn to use generics.
List list = new ArrayList();
for (Iterator it = list.iterator(); it.hasNext();) {
String[] strs = (String[])it.next();
// do stuff with strs
}
// becomes
List<String[]> list = new ArrayList<String>();
for (Iterator<String[]> it = list.iterator(); hasNext();) {
String[] strs = it.next();
// do stuff with strs
}
// and with enhanced for loop, becomes
List<String[]> list = new ArrayList<String>();
for (String[] strs : list) {
// do stuff with strs
}
http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html
http://java.sun.com/j2se/1.5.0/docs/guide/language/foreach.html
jverda at 2007-7-12 15:49:27 >
