Making Java enjoyable

malte on 2003-04-07T15:55:26

What I always hated about Java is that you can't say "I'm going to iterate over this thing" in a single expression. Actually, you can't say it at all. You have to know a lot about how the collection and iterator iterfaces behave, to write it down. This feels really wrong. One of the nice things about statically typed languages is, that you know at compile time that something can be iterated upon, so you might as well be allowed to write it down. Fortunately, perl came to help:

Construct like:

foreach String name (aCollection) {

are turned into

Iterator it = aCollection.iterator();

while(it.hasNext()) {
		String name = it.next();

The script does it very naively. It doesn't really know about Java syntax, but it works for me.


casting

Wallie on 2003-04-08T07:13:37

String name = it.next();

Should probably be:

String name = (String) it.next();

mark

Re:casting

malte on 2003-04-08T07:24:10

obviously