Looking forward to Java 5+ support in Notes

I’m currently trying to figure out some replication issues for a customer and to help me diagnose the problems I’m writing a reporting tool. I hope to be able to share the tool shortly as it has proven an invaluable tool to help monitor cluster replication as well.

The tool is written in Eclipse using Java and I wrote it using some of the features of Java 5 such as the enhanced for-loop, autoboxing and generics since it was to be a one time thing running from a console. Well as with all quickies – they turn out to stick around…

Now the customer would like to keep monitoring the replication and by far the easiest way is to schedule it using an agent. This however meant that I had to port the code to Java 1.4.2… 😦 I don’t think you fully appreciate the new features of Java 5 until you have to revert to Java 1.4.2.

For those not in the know in Java 5 you can use an enhanced version of the for-loop to loop all types of java.util.Collection instances and arrays. This means that instead of writing:

public void loop(Collection my_col) {
  Iterator ite=my_col.iterator();
  while (ite.hasNext()) {
    Customer c = (Customer)ite.next();
    c.bill();
  }
}
...or...
public void loop(Collection my_col) {
  for (Iterator ite=my_col.iterator(); ite.hasNext(); ) {
    Customer c = (Customer)ite.next();
    c.bill();
  }
}

you can simply write

public void loop(Collection<Customer> my_col) {
  for (Customer c : my_col) {
    c.bill();
  }
}

Isn’t that nice… Apart from being shorter is much easier to read and understand. Also the added use of generics (i.e. specifying that the passed collection contains Customer objects by using the bracket notation) means no more casting of objects all the time.

Can’t wait for Java 5+ support in Notes/Domino. I wonder what the Java level is in Hannover…