Fluent API with inheritance and generics
问题 I'm writing a fluent API to configure and instantiate a series of "message" objects. I have a hierarchy of message types. To be able to access method of subclasses when using the fluent API, I used generics to parametrize the subclasses and make all fluent methods (that start with "with") return the generic type. Note that I omitted most of the body of the fluent method; a lot of configuration goes on in them. public abstract class Message<T extends Message<T>> { protected Message() { }