Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Scala 2.8 implicit prioritisation, as discussed in: http://www.scala-lang.org/sid/7
object Low {
def low = "object Low"
def shoot = "missed!"
}
object High {
def high = "object High"
def shoot = "bulls eye!"
}
trait LowPriority {
implicit def intToLow(a: Int): Low.type = Low
}
object HighPriority extends LowPriority {
implicit def intToHigh(a: Int): High.type = High
}
import HighPriority._
val a: Int = 1
print((a.low, a.high, a.shoot)) // (object Low,object High, bulls eye!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment