Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 353
yura Avatar asked Aug 31 '11 07:08

yura


2 Answers

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).

like image 133
Kevin Wright Avatar answered Sep 27 '22 17:09

Kevin Wright


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
like image 42
soc Avatar answered Sep 27 '22 17:09

soc