Java gem of the day: Java's got for!!!

jdavidb on 2007-12-21T15:24:59

Java has a for that iterates over arrays! (And over any object implementing the Iterable interface.)

String[] strings = {"First", "Second", "Third"};
		for (String s: strings)
			System.out.println(s);

This is spectacular. This most definitely did not exist the last time I looked closely at Java (circa 2001, I think, although most of the Java coding I did happened in 2002-3 or so).

Java's added piece after piece of Perl syntax. :) I knew that regular expressions had been added at some point, although I never looked at them, and I figured that like most languages where regexes are added they were probably garbage rather than being first class parts of the language. (Perl is the only language I know that has benefitted over a certain baseline from having first class regular expression variables added to it. Although regexes that are only accessible through unwieldy functions are technically better than no regexes at all, they're still not much good to you if noone uses them, yourself included, because they are too hard to use.)

For people like me who haven't checked out Java in a long, long time, it would behoove you to check out Java's version history to see what's been added.


5+ is a lot more usable

Dom2 on 2007-12-22T08:47:06

I've been doing mostly Java for the last year. I wouldn't want to go back to pre-Java5. Generics are often slated by the Java people, but the alternative is casts everywhere. For something that's supposed to be a typesafe language, that's ridiculous.

-Dom