keith chapman wrote:
>     > In my view this is highly inefficient, especially if you have
>     plenty of
>     > services in the system. Wouldn't it be better to fix the API and
>     return
>     > a Map instead of a HashMap? If we did that we could simple return
>     > allServices instead of returning a copy of it.
> 
>     You don't want to return an actual reference to a mutable object
>     that backs a
>     significant data model - otherwise people could just get that Map and
>     (mistakenly or maliciously) randomly add and delete services.
>  
> Agreed. But now that we've been doing it people may have code that
> expect it to be there. So we need a mechanism for returning this map.

Um - we aren't currently returning the actual Map, we're returning a clone of
it (just done manually instead of using clone()).  You had suggested
returning the actual Map itself, which is what I was reacting to above.  I'm
not saying the API should go away.

<rant>
Of course, if we had any kind of reasonable JavaDoc, there would be a clear
indication in the API docs that the returned HashMap was in fact a clone and
that inserting or removing things from it would have no effect on the system.
</rant>

Thanks,
--Glen

Reply via email to