I'm looking at some Java classes that have the following form:
public
abstract
class A <E extends A<E>> implements Comparable <E> {
public final int compareTo( E other ) {
// etc
}
}
public
class B extends A <B> {
// etc
}
public
class C extends A <C> {
// etc
}
My usage of "Comparable" here is just to illustrate a possible use of the generic parameter "E". Does this usage of generics/inheritance have a name? What is it used for?
My impression is that this allows the abstract class to provide a common implementation of a method (such as compareTo) without having to provide it in the subclasses. However, in this example, unlike an inherited method it would restrict subclasses to invoking compareTo on other instances of the same subclass, rather than any "A" subclass. Does this sound right?
Anyway, just curious if any gurus out there have seen this before and know what it does.
Thanks!