| d2r diego's weblog |
my favorite Java 5 changeI used Java 5 (with Eclipse 3.1) for the code I wrote last week to use as example for manifold, and there's no question: the enhanced for loop, combined with generics, rocks. Aside from the basic difference of going from (Note, use of an inline iterator is also common): tothere's also the cooler use of it to iterate over the contents of a HashMap, so instead of doingyou can doWhich is much more concise, and clear IMO. Very cool.
Categories: soft.devPosted by diego on December 20 2004 at 6:19 PM Comments (please see the comments & trackback policy).
Why not use the entry set? HashMap m = new HashMap();
HashMap m = new HashMap();
Indeed. :) I was going to mention that and I forgot. I don't use that because it sounds slightly "dirty" to me, dependent on the internal structure of the hash which is not something that is technically exposed. But it's also a good option. :) Posted by: Diego at December 20, 2004 8:33 PMSeems like something ate your type declarations in the HashMap<String, Vector> declarations ;) Posted by: Tom Klaasen at December 21, 2004 9:49 AMI'm pretty sure entrySet isn't dependent on the internal structure of HashMap. I think Map.Entry objects are created for each entry when you call entrySet. Posted by: Keith Lea at December 21, 2004 10:57 PMIsn't this Java getting C#'s foreach()? BTW I'm not saying stole (after all C# copies many ideas from Java). Still it does save a few lines of code. Posted by: Mark Levison at December 21, 2004 11:11 PMCopyright © Diego Doval 2002-2007.
|
