Oliver said:
"affect similar changes across all occurrences" would probably be
undesirable in the example of
public List getEmptyList() {
return new ArrayList();
}
because you might call a method called "getEmptyList", and then find
that it is not empty! (if another thread modified the a different
instance, but that modification is reflected across all instances of the
list).
However, I'd argue that getEmptyList() is indeed idempotent if you
take the definition of "always does the same thing, no matter how many
times you call it".
But that is not the definition of idempotent. An idempotent
transformation I is one such that I^2 = I. Applied to a method, that
would mean that the second call has no effect, not that it does the same
thing as the first call. A method such as Arrays.sort() is idempotent.
Almost all (reasonable) methods will satisfy the definition the way you
have written it. E.g., a method to square a value "always does the same
thing" but is not idempotent.
I've not sure that the term idempotent applies to a method that does not
accept arguments or modify internal state. For the above getEmptyList()
method, the heap is modified in a different way for each invocation;
that may be nitpicking however.
Ray