Skip to content

Commit 2027e3a

Browse files
authored
Merge pull request #3103 from SethTisue/faq-this-type-tweak
FAQ: tweak answer about this.type
2 parents 68a41e8 + fc1f78d commit 2027e3a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

_overviews/FAQ/index.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,14 +292,16 @@ For more details, see the Scala Style Guide, [here](https://docs.scala-lang.org/
292292

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

295-
First, note that using `this.type` won't work. People often try that,
296-
but `this.type` means "the singleton type of this instance", a
297-
different and too-specific meaning. Only `this` itself has the
298-
type `this.type`; other instances do not.
299-
300-
What does work? Possible solutions include F-bounded polymorphism
301-
_(familiar to Java programmers)_, type members,
302-
and the [typeclass pattern](http://tpolecat.github.io/2013/10/12/typeclass.html).
295+
Using `this.type` will only work if you are returning `this` itself.
296+
`this.type` means "the singleton type of this instance". Only `this`
297+
itself has the type `this.type`; other instances of the same class do
298+
not.
299+
300+
What does work for returning other values of the same type?
301+
302+
Possible solutions include F-bounded polymorphism _(familiar to Java
303+
programmers)_, type members, and the [typeclass
304+
pattern](http://tpolecat.github.io/2013/10/12/typeclass.html).
303305

304306
This [blog post](http://tpolecat.github.io/2015/04/29/f-bounds.html)
305307
argues against F-bounds and in favor of typeclasses;

0 commit comments

Comments
 (0)