It said this:
List(1,4,2,3).sorted
can be done because in trait Ordering defined this:
implicit object Int extends IntOrdering with CachedReverse[Int]
but if class Int can use this implicit object,isn't it have to write this?
import scala.math.Ordering
In the example of book 《programming in scala》:
class PreferredPrompt(val preference: String)
object Greeter {
def greet(name: String)(implicit prompt: PreferredPrompt) = {
println("Welcome, " + name + ". The system is ready.")
println(prompt.preference)
}
}
object JoesPrefs {
implicit val prompt = new PreferredPrompt("Yes, master> ")
}
the "implicit val prompt" defined in object JoesPrefs,so if want to write this:
Greeter.greet("Joe")
have to write:
import JoesPrefs._
so
implicit object Int extends IntOrdering with CachedReverse[Int]
defined in scala.math.Ordering
so shouldn't have write
import scala.math.Ordering
in class Int?Thanks!