i had the following code that i wanted to convert to the new enhanced for loop:
private String myMethod(Collection c){
for(Iterator<String> it = c.iterator(); it.hasNext();){
String s = it.next();
...
}
}
so i rewrote it like this:
private String myMethod(Collection c){
for(String s : c){
...
}
}
but that code gave me the following "error" in eclipse:
Type mismatch: cannot convert from element type Object to String
here's the final, error-free solution:
private String myMethod(Collection<String> c){
for(String s : c){
...
}
}
IT, computer and programming tutorials and tips that i couldnt find anywhere else using google, from my daily work as a Senior Developer of solutions using Java and Linux.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment