T - the type of objects that this object may be compared to.public interface Comparative<T> extends Comparable<T>
Comparable interface.
To check if a Comparable value
is greater than another you need to write:
if( a.compareTo(b) > 0 ) // Do something...
This type of statements is long to write, can make the code difficult to understand and is prone to errors.
This interface adds the following default methods:
This way the same statement will become
if( a.gt(b) ) // Do something...
| Modifier and Type | Method and Description |
|---|---|
default boolean |
eq(T other)
Tells if this object is equal to the given object.
|
default boolean |
ge(T other)
Tells if this object is greater or equal than the given object.
|
default boolean |
gt(T other)
Tells if this object is greater than the given object.
|
default boolean |
le(T other)
Tells if this object is less or equal than the given object.
|
default boolean |
lt(T other)
Tells if this object is less than the given object.
|
default boolean |
ne(T other)
Tells if this object is not equal to the given object.
|
compareTodefault boolean lt(T other)
other - the object to be compared.true it this is less than other.NullPointerException - if other is null.default boolean le(T other)
other - the object to be compared.true it this is less or equal than other.NullPointerException - if other is null.default boolean eq(T other)
other - the object to be compared.true it this is equal to other.NullPointerException - if other is null.default boolean ne(T other)
other - the object to be compared.true it this is not equal to other.NullPointerException - if other is null.default boolean ge(T other)
other - the object to be compared.true it this is greater or equal than other.NullPointerException - if other is null.default boolean gt(T other)
other - the object to be compared.true it this is greater than other.NullPointerException - if other is null.Copyright © 2011–2020 Nerd4j. All rights reserved.