1

Take a look at this class declaration:

public abstract class AbstractTargetBuilder<T extends AbstractTargetBuilder<T, S>, S extends Target> {
...
}

The type T is defined to be a subtype of AbstractTargetBuilder<T,S>. What's the use of this pattern?

This code belongs to Spotlight library: https://github.com/TakuSemba/Spotlight/blob/master/spotlight/src/main/java/com/takusemba/spotlight/target/AbstractTargetBuilder.java

saga
  • 1,933
  • 2
  • 17
  • 44
  • 1
    In the context of builders, this is most often used to allow method chaining, whilst preserving the subclass of the builder that you're using. The methods of the builder will be declared as returning `T`, which can be interpreted as a "self" type (even though you can't enforce that it really is the self type; you're just relying upon people extending the class to be good citizens). – Andy Turner Sep 20 '18 at 09:45

0 Answers0