Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scala type which can only be extended by an object, not by a non-abstract type ...
scala> class Foo { self: Singleton => }
defined class Foo
scala> class Bar extends Foo
<console>:12: error: illegal inheritance;
self-type Bar does not conform to Foo's selftype Foo with Singleton
class Bar extends Foo
^
scala> object Bar extends Foo
defined object Bar
scala>
@RSchulz
Copy link

RSchulz commented Jun 7, 2016

Seems like magic, since if you try to extend Singleton directly, you're chastised that Singleton is final! (Nor does it appear in the ScalaDoc!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment