For one, initializing array members within the enhanced for loop does not really initialize them. Thus, the following code
String[] sa = new String[2];
for(String s : sa) {
s = "hello";
}
for(String s : sa) {
System.out.println(s);
}
prints "null" twice instead of "hello". Despite of this pitfall, the enhanced for loop is a welcome addition.
Notwithstanding the purportedly increased safety they bring to the language, I can't say the same about generics. Java generics seem so much weaker and confusing than generics in the Ada language, where they are a core language feature, not an awkward afterthought.
Generics seem as one of those half-baked features capable of making the life of programmers miserable. With more experience, I hope my initial concerns about generics will reveal themselves to be unjustified.
No comments:
Post a Comment