class A { ... }
class B extends A implements Comparable<A> {
int compareTo(A aobject) { ... }
}
Usually we implement Comparable
with a type-parameter of B
. But java allows using a super class, as well.
Is there a scenario where I really need to do something like this?
For instance if you have also:
Class C extends A implements Comparable<A> {
int compareTo(A aobject) {
/* Implementations */
}
you could compare objects of class B
and C
together either with c.compareTo(b)
or with b.compareTo(c)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With