Interface Self<S extends Self<S>>

Type Parameters:
S - the type of the implementing class.
All Known Subinterfaces:
BoundedGene<A,G>, Gene<A,G>, NumericGene<N,G>
All Known Implementing Classes:
AnyGene, BitGene, CharacterGene, DoubleGene, EnumGene, IntegerGene, LongGene

public interface Self<S extends Self<S>>
This interface defines a recursive generic type S, which represents the type of the implementing class.
interface Foo<T extends Foo<T>> extends Self<T> {
    // ...
}
Using the 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

    Modifier and Type
    Method
    Description
    default S
    Return a reference of this object as the declared generic type S.
  • Method Details

    • self

      default S self()
      Return a reference of this object as the declared generic type S.
      Returns:
      the this reference as the generic type S
      Throws:
      ClassCastException - if the interface is not used as intended and (this instanceof S) == false