The elidable annotation takes an Int parameter which specifies the priority of the method. The lower the integer the more likely the method would be removed during compilation. The elidable object defines several values that are used in our example.
When compiling with the -Xelide-below
To try the following example copy the example into a scala file (elidable.scala for example) and compile as indicated below:
- package example
- import scala.annotation.elidable
- import scala.annotation.elidable._
- object ElidableExamples {
- @elidable(ALL) def all = println("all")
- @elidable(ASSERTION) def assertion = println("assertion")
- @elidable(CONFIG) def config = println("config")
- @elidable(FINE) def fine = println("fine")
- @elidable(FINER) def finer = println("finer")
- @elidable(FINEST) def finest = println("finest")
- @elidable(INFO) def info = println("info")
- @elidable(OFF) def off = println("off")
- @elidable(SEVERE) def severe = println("severe")
- @elidable(WARNING) def warning = println("warning")
- }
- object Main extends Application {
- println("starting")
- import ElidableExamples._
- all
- assertion
- config
- fine
- finer
- finest
- info
- off
- severe
- warning
- println("ending")
- assert(false, "boom!")
- }
Output from scalac elidable.scala && scala example.Main
starting
assertion
off
ending
java.lang.AssertionError: assertion failed: boom!
at scala.Predef$.assert(Predef.scala:93)
at example.Main$.(elidable.scala:34)
at example.Main$.(elidable.scala)
at example.Main.main(elidable.scala)
Output from scalac -Xelide-below 0 elidable.scala && scala example.Main
starting
assertion
config
fine
finer
finest
info
off
severe
warning
ending
java.lang.AssertionError: assertion failed: boom!
at scala.Predef$.assert(Predef.scala:93)
at example.Main$.(elidable.scala:34)
at example.Main$.(elidable.scala)
at example.Main.main(elidable.scala)
Output from scalac -Xelide-below 1000 elidable.scala && scala example.Main
starting
assertion
off
severe
ending
java.lang.AssertionError: assertion failed: boom!
at scala.Predef$.assert(Predef.scala:93)
at example.Main$.(elidable.scala:34)
at example.Main$.(elidable.scala)
at example.Main.main(elidable.scala)
Output from scalac -Xelide-below 3000 elidable.scala && scala example.Main
starting
off
ending