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
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).
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With