- Type Parameters:
S- the type of the implementing class.
- All Known Subinterfaces:
BoundedGene<A,,G> FlatTree<V,,T> Gene<A,,G> NumericGene<N,,G> Tree<V,,T> TreeGene<A,G>
- All Known Implementing Classes:
AbstractTreeGene,AnyGene,BigIntegerGene,BitGene,CharacterGene,DoubleGene,EnumGene,FlatTreeNode,IntegerGene,LongGene,ProgramGene,TreeNode
public interface Self<S extends Self<S>>
This interface defines a recursive generic type
Using the
S, which
represents the type of the implementing class.
interface Foo<T extends Foo<T>> extends Self<T> {
// ...
}
Self interface in this case makes it clear that the generic
type T of the interface Foo represents the concrete type of
the class, implementing the interface Foo.
If the interface is used as intended, the following generic min method
can be implemented as a default method.
interface Foo<A extends Foo<A>> extends Self<A>, Comparable<A> {
// ...
default A max(final A other) {
return compareTo(other) > 0 ? self() : other;
}
}
- Since:
- 7.0
- Version:
- 7.0
-
Method Summary
-
Method Details
-
self
Return a reference ofthisobject as the declared generic typeS.- Returns:
- the
thisreference as the generic typeS - Throws:
ClassCastException- if the interface is not used as intended and(this instanceof S) == false
-