Friday, June 03, 2005

Generics and EFL Save Me Code

I know that Generics and the Enhanced For Loop have been blogged to death but since I just now really started using them here and there I just wanted to publically state my thanks to those Sun guys that improved the language for me.

The old way:
-------------


for(int i=0; i<workstationlist.size(); i++){
list.add(new SelectItem(
((Workstation)workstationList.get(i)).getId(),
((Workstation)workstationList.get(i)).getWorkstation()));
}

The new way:
--------------

for(Workstation w : workstationList) {
list.add(new SelectItem(w.getId(), w.getWorkstation());
}


Gotta love it!

No comments: