The implementation of default methods
Doug Lea
dl at cs.oswego.edu
Sat Dec 15 04:01:29 PST 2012
On 12/15/12 01:50, David Holmes wrote:
>>> 2. Document "The default implementation behaves as if..." (Or whatever
>>> Doug's
>>> proposed wording is.)
>>
>> In j.u.c, we always say "is behaviorally equivalent to" but I dropped
>> the "behaviorally" in Map candidate because someone once told me
>> it was overly pedantic :-)
>>
Little style notes:
1. These seem to be more easily decodable when written in
"third person" user-centered form. As in, for Map.putIfAbsent:
/**
* If the specified key is not already associated with a value,
* associates it with the given value. The default implementation
* is equivalent to, for this {@code map}:
*
* <pre> {@code
* if (!map.containsKey(key))
* return map.put(key, value);
* else
* return map.get(key);}</pre>
...
2. Often, little code snippets like this are the simplest
way to say what you mean. But there's no strict need for this.
Sometimes words describing effects are simpler. Or mixtures.
I did this among other places in Map.merge to avoid the
messiness of putting a retry loop in the code snippet.
-Doug
More information about the lambda-libs-spec-observers
mailing list