'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]
# 1
It means that whatever you get from that iterator as a result, it's not a String[].
CeciNEstPasUnProgrammeura at 2007-7-12 15:49:27 > top of Java-index,Java Essentials,Java Programming...
# 2
But there should be a String[] array in it. In jdk 1.5 I converted the Object[] array to a String[] array.
mathos2a at 2007-7-12 15:49:27 > top of Java-index,Java Essentials,Java Programming...
# 3
Sometimes 'Y' or 'W'? Sounds like it has to do with generics. Can you post a small (<1 page) example program demonstrating your problem?
Hippolytea at 2007-7-12 15:49:27 > top of Java-index,Java Essentials,Java Programming...
# 4

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.

mathos2a at 2007-7-12 15:49:27 > top of Java-index,Java Essentials,Java Programming...
# 5

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 > top of Java-index,Java Essentials,Java Programming...