News for hackers. Stuff that matters.
Re:Why Generics? by ben509 on Wednesday July 31, 2019 @05:56PM (#20578967)
> The only truly unforgiveable one is UnsupportedOperationException. The guy who wrote the collections API for Java didn't know the first thing about the Liskov Substitution Principle, and gave the world an implementation that violates it...

The implementation perfectly follows it because the LSP simply requires identical behavior, and the contract clearly states it may[1] throw an exception. All the implementations "may" throw an exception. Sorry, but they correctly lawyered the LSP.

> I came up with around 20% more than the selected design.

But `add` can throw 5 different exceptions depending on restrictions your implementation wants to place on a given collection, does it allow for all that? In terms of making an interface that was small and reusable by many projects, runtime exceptions are a pretty good compromise for a standard library.

[1]: https://docs.oracle.com/javase/7/docs/api/java/util/Collecti...

Re:Why Generics? by hinkley on Wednesday July 31, 2019 @06:48PM (#20579405)
No they most definitely are not. One implementation receives a message. The other categorically rejects it. I cannot substitute them.
Re:Why Generics? by ben509 on Thursday August 01, 2019 @10:32PM (#20590306)
Yes, those are the same behavior. Both of them "may" accept it and "may" reject it, and "may" includes both "always" and "never".

It is correct to the letter of LSP, but not the spirit of it, and this was a conscious decision; contrary to your original claim, they understood the principle perfectly well.