Diasparsoft Logo Let's write software that people understand.

Home | Contact

Training

JUnit support

Outsourcing

The work that Diasparsoft did for us was outstanding. We are now using the software on a daily basis and their work could well have a dramatic impact on the Reds' organization in the near future.Cincinnati Reds Baseball Club.


Publications

Tips & Tricks

Diasparsoft Toolkit

What is Diaspar?

Interesting Bits RSS

Home » Archives » October 2004 » Java 5.0: A little bit of syntactic sugar

[Previous entry: "UGOT: A familiar approach to testing from Frank Cohen"] [Next entry: "Subversion on Fedora Core 2"]

10/15/2004: "Java 5.0: A little bit of syntactic sugar"


Fellow Agilist and expert Java programmer Mike Bowler sent me this e-mail, and I thought I'd pass it along to you folks.


One of the tricks that I know we both use when writing tests is to use Arrays.asList() to prepopulate a list.

Arrays.asList( new Object[] {"one", "two"} );

I just realized that Java 5.0 has changed the syntax of asList() to use the new varargs so now it's possible to write this instead:

Arrays.asList( "one", "two" );

Just one of those little things that makes coding more pleasant ;-)


Thanks to Mike for pointing this out. Although I'm not a fan of variable argument lists, I like the nicer code here. It's closer to PHP syntax for declaring an array, which is relatively compact. I would much prefer Ruby-style syntax for literal list values:

["one", "two"]