[stringtemplate-interest] Iterating over a map

Tom Bentley tom at egressive.com
Tue May 3 14:48:58 PDT 2005


> Hi Tom.  Yeah, that's why i was thinking we'd need that temp object.  I 
> don't like having to assume something is a map, but i already break this 
> rule by allowing object.property ;)

Yeah, I saw the special case code in there, worrying about Hashtables 
and the like.

There are quite a few 'safe' (without side-effects) implementations of 
Map in J2SE to worry about; Hashtable, HashMap, TreeMap, LinkedHashMap, 
possibly IdentityHashMap (though that's something of a special case). 
IMHO, supporting the TreeMap and LinkedHashMap is reasonably important, 
since it gives some sort of control over iteration order.

On the other hand, it seems a shame that people have to shoehorn their 
model into a HashMap/Hashtable: Fundementally, you can't know for sure 
that the getters people write (and StringTemplate merrily calls) don't 
have weird side-effects, so part of me says just to assume the Map 
interface regardless: If people write a Map whose get() has side-effects 
that's their look-out.

Just my 2 cents.

Cheers,

Tom


More information about the stringtemplate-interest mailing list