Skip to content

Instantly share code, notes, and snippets.

@milessabin
Created June 6, 2016 11:04
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save milessabin/ace99b2feaa6e4e8822cda08d79cb91e to your computer and use it in GitHub Desktop.
Save milessabin/ace99b2feaa6e4e8822cda08d79cb91e to your computer and use it in GitHub Desktop.
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>
@LouisJB
Copy link

LouisJB commented Jun 6, 2016

well I never!

@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