[concurrency-interest] Reference/IdentityMap toString

Jason Mehrens jason_mehrens at hotmail.com
Wed Aug 18 14:14:54 EDT 2010

Debuging and logging are key areas.  Take the following:
Map<Integer, Integer> eq = new HashMap<Integer, Integer>();
eq.put(new Integer(1), new Integer(1));

Map<Integer, Integer> id = new IdentityHashMap<Integer, Integer>();
id.put(new Integer(1), new Integer(1));
I think it would be ideal if this printed false, false and not false, true.  Changing the toString implementation to use identity strings would mean that CCHM.toString would be safe from stack overflow, would not unknowingly acquire an internal lock, and would have a more predictable runtime (Map<K, Collection<E>>.  CCHM hashCode and equals enjoy those benefits when in identity mode so why shouldn't CCHM.toString?
> Date: Wed, 18 Aug 2010 17:22:41 +0200
> From: kasper at kav.dk
> To: concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] Reference/IdentityMap toString
> On 17/08/10 04.23, Jason Mehrens wrote:
> > Should the string representation of a map (entries and collection views)
> > describe strictly just the contents or express the equivalence
> > relationship of how the map views its entries? Specificity, since the
> > CustomConcurrentHashMap can be created with an IDENTITY equivalence or
> > EQUALS equivalence it would seem to me that one natural way to express
> > this difference would be to have the map create an identityToString for
> > a key or value when using an IDENTITY equivalence. Is it worth adding
> > another method to CCHM.Equivalence to support custom strings?
> >
> Could you come up with some kind of usage scenario?
> I can't recall i've ever used map.toString() for anything but debugging.
> And if I ever wanted another string representation I would just copy the 
> one from AbstractMap/AbstractCollection and customize it.
> Cheers
> Kasper
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100818/711d0590/attachment.html>

More information about the Concurrency-interest mailing list