lambda-dev Digest, Vol 31, Issue 5

James Shaw js102 at zepler.net
Tue Jun 5 02:43:12 PDT 2012


On 4 June 2012 22:06, David Conrad <drconrad at gmail.com> wrote:

> I have been thinking of something like this, but didn't want to bug you
> guys too much. :)
>
> I have an interface I've used, Compare<T> extends Comparable<T>, which has
> greaterThan(T) and lessThan(T) methods. These would fit very nicely as
> default
> methods on Comparable, either with those names or the beanier isLessThan
> etc.
>
> But depending on choices, you can end up with one of these:
>
> if (a.lessThan(b) || a.equals(b)) ...
> if (a.isLessThan(b) || a.equals(b)) ...
> if (a.lessThanOrEquals(b)) ...
> if (a.isLessThanOrEquals(b)) ...
> if (a.lessOrEquals(b)) ...
> if (a.isLessOrEquals(b)) ...
>
Or-ing Comparable methods with equals() seems potentially dangerous given
that a class may implement Comparable but not override equals().


More information about the lambda-dev mailing list