lambda-dev Digest, Vol 31, Issue 5
David Conrad
drconrad at gmail.com
Mon Jun 4 14:06:22 PDT 2012
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)) ...
It would be very un-Java-like, but the names lt, gt, lte, and gte come to
mind.
isGreaterThanOrEquals is a beast, but I guess it's the most Java-y. :(
David
On Mon, 4 Jun 2012 11:26:17 -0400, Brian Goetz <brian.goetz at oracle.com
> wrote:
>
> Good suggestion. We'll take a look.
>
> > There is something we can do right now: adding default methods
> > isGreaterThan, isLessOrEqualThan to Comparable will allow us
> > to write
> >
> > if (a.isGreaterThan(b)) { ... }
> >
> > which is way better than
> >
> > if (a.compareTo(b) > 0) { ... }
>
>
More information about the lambda-dev
mailing list