Skip to content

FAQ: small improvement in 'this type' answer #2195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion _overviews/FAQ/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,12 @@ For an in-depth treatment of types vs. classes, see the blog post

### How can a method in a superclass return a value of the “current” type?

Possible solutions include F-bounded polymorphism
First, note that using `this.type` won't work. People often try that,
but `this.type` means "the singleton type of this instance", a
different and too-specific meaning. Only `this` itself has the
type `this.type`; other instances do not.

What does work? Possible solutions include F-bounded polymorphism
_(familiar to Java programmers)_, type members,
and the [typeclass pattern](http://tpolecat.github.io/2013/10/12/typeclass.html).

Expand Down