Java: returning subclass in superclass method signature

This is a good question and a real problem.

The easiest way to deal with it in Java likely involves the use of generics, as mentioned in Jochen’s answer.

There’s a good discussion of the issue and a reasonable solution in this blog entry on Using Inheritance with Fluent Interfaces, which combines generics with the definition of a getThis() method overriden in builder subclasses to solve the problem of always returning a builder of the correct class.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)