yura
yura

Reputation: 14655

Where can I find list of all special traits in Scala?

Special means that they give you functionality which is impossible to get otherwise, so they treat by compiler in special way. Examples: 'DelayedInit' - convert all init code to main methods, 'Dynamic' - proxy of all methods etc

Upvotes: 9

Views: 400

Answers (2)

soc
soc

Reputation: 28443

There is also scala.Singleton.

It is a final trait and cannot be used normally while writing code, but everyone using some a singleton like object Foo has already used it indirectly.

Singleton is used by the compiler to extend a singleton, therefore:

scala> object Foo
defined module Foo

scala> Foo.isInstanceOf[Singleton]
res0: Boolean = true

Upvotes: 10

Kevin Wright
Kevin Wright

Reputation: 49705

At present, the only special traits I'm aware of are DelayedInit and Dynamic.

Anything inheriting from these traits also gets special treatment by the compiler, as with App, which subclasses DelayedInit.

It's worth noting that any trait could potentially be used as a marker by some library, framework, or compiler plugin to "give you functionality which is impossible to get otherwise". These two are the only traits that are specially recognized by the default compiler though.

As well as marker traits, there are some annotations that get treated specially, the scala.annotation and scala.reflect are good places to find these, there's also the @specialized annotation in the scala package and several in compiler plugins (such as delimited continuations).

Upvotes: 12

Related Questions