title: How Ordering works in Scala
body: <p>I created the following class and an object which implements Ordering</p>
  
  <pre><code>//class person
  class Person (s:String, i:Int, d:Date) {
    val name = s
    override def toString = name
    val age = i
    val dob = d
  }
  /*
  logic for how to compare two Person objects. Their names will be compared first. If names are same, then their age will be compared. If their age is also same, then their date of birth will be compared. Note that we could have used any other logic to compare two person objects.
  */
  
  implicit object myPersonOrdering extends Ordering[Person] {
    override def compare(x: Person, y: Person) = if (x.name.compareTo(y.name) == 0) {
      if (x.age.compareTo(y.age) == 0) {
        x.dob.compareTo(y.dob)
      } else (x.age.compareTo(x.age))
    } else (x.name.compareTo(y.name))
  
  }
  
  //create a list of Persons
  val a1 = new Person("Andy",11, new Date())
  val a2 = new Person("ann",12,new Date())
  val a3 = new Person("Beth",31, new Date())
  val a4 = new Person("Danny",10, new Date())
  val a5 = new Person("peter",1, new Date())
  
  val la = List(a1,a2,a3,a4, a5)
  
  la.sortBy(x=&gt;x)
  </code></pre>
  
  <p>I am trying to understand where the function compare is used in sortBy. Looking at source code of SeqLike.scala, the method sortBy calls method sorted which calls method java.util.Arrays.sort(arr, ord.asInstanceOf[Ordering[Object]]). Does  compareTo get called in Java code?</p>