Having played around with 1.5 for a while I've
come across a couple of things that are really
annoying.
Firstly, deleting from a list:
for (String s : strings) {
if (foo(s)) strings.remove(s);
}
doesn't work and never has, since you're supposed
to use the lists iterator to remove objects. It
still does annoy me that the mentioned code
doesn't work. I know I can do it with code like
this:
Iterator <String> i = strings.iterator();
while (i.hasNext()) {
String s = i.next();
if (foo(s)) i.remove();
}
but that's not the point. The point is that it
should be possible to remove things from a list
via the for-loop, or even better, if Collections
had a filter(Collection <T> c, Filter f) method
which deleted all elements of c which did (or did
not) return true for the filter f.
Secondly, overloading:
A class containing these two methods will not
compile
void foo(List<String> list) {
...
}
void foo(List<Integer> list) {
...
}
since the both get rewritten to (I guess)
void foo(List list) {
...
}
I find this too a bit annoying.
I guess my point is that generics in Java is nice
but it still has some ways to go.
|
for(Iterator <String> i = strings.iterator(); i.hasNext(); ) {
if (foo(i.next())) i.remove();
}
--but that's not the point. The point is that it
--should be possible to remove things from a list
--via the for-loop