Default method survey results
Yuval Shavit
yshavit at akiban.com
Sat Aug 18 01:53:13 PDT 2012
On Sat, Aug 18, 2012 at 3:35 AM, "Zdeněk Troníček" <tronicek at fit.cvut.cz>wrote:
>
> 2) Iterator with remove() that throws UOE breaks the Liskov substitution
> principle. Mutable iterator is not a special case of immutable iterator.
Sorry for beating this horse, but I fail to see why this is the case.
Invoking remove() on an Iterator is obligated to do one of two things:
remove the last element that next() returned, or throw UOE. An iterator
with remove() that throws UOE conforms to this contract, and can be
replaced with any other iterator *about which nothing is known other than
it's an Iterator*.
Taking wikipedia at face value, the LSP states:
Let be q(x) a property provable about objects x of type T. Then q(y)
should be provable for objects y of type S where is S a subtype of T.
Let q(n) be "remove() throws UOE or removes the last element returned by
next()." I can prove q(x) for objects x of type Iterator, since that is the
contract of Iterator.remove(). If some type S has a method remove() that
always throw UOE, then I can by definition prove the property "remove()
throws UOE" for objects y of S. In that case, I can also trivially prove
that "remove() always throws UOE or removes the last element returned by
next()" for objects y of S. So the LSP holds.
More information about the lambda-dev
mailing list