FYI: you can avoid the unchecked cast by having an abstract T self() implemented by subclasses as self() {return this;}