Skip to content

Instantly share code, notes, and snippets.

@ljank
Last active August 24, 2017 10:20
Show Gist options
  • Save ljank/e9117819e583fcc1cf0a44ac722bf77e to your computer and use it in GitHub Desktop.
Save ljank/e9117819e583fcc1cf0a44ac722bf77e to your computer and use it in GitHub Desktop.
scala> class Parent { def f = this }
defined class Parent
scala> class Child extends Parent { def newF = this }
defined class Child
scala> val c = new Child
c: Child = Child@5b966ac7
scala> c.newF
res4: Child = Child@5b966ac7
scala> c.f.newF
<console>:11: error: value newF is not a member of Parent
c.f.newF
^
scala> class Parent { def f: this.type = this }
defined class Parent
scala> class Child extends Parent { def newF = this }
defined class Child
scala> val c = new Child
c: Child = Child@40452835
scala> c.f.newF
res7: Child = Child@40452835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment