Hello i write followed code to iterate a list of nodes
public class RootImpl {
private List nodes = new ArrayList<String>();
public void processData(Object object) {
for (String node : nodes){
}
}
}
And this code won’t compile and give me errors in line: for (String node : nodes)
java: incompatible types
required: java.lang.String
found: java.lang.Object
is this code is wrong?
You must define the variable with the appropiate types:
The compiler is not able to see that
nodeshas been assigned anArrayList<String>, so it interprets it as a genericList<Object>and issues such an error.