Skip to content

Instantly share code, notes, and snippets.

@masayuki038
Created July 16, 2012 13:29
Show Gist options
  • Save masayuki038/3122729 to your computer and use it in GitHub Desktop.
Save masayuki038/3122729 to your computer and use it in GitHub Desktop.
Ordered[A] and Comparable[A]
package net.wrap_trap.scala.examples
object OrderedComparableTest {
def main(args : Array[String]) : Unit = {
val s1 : String = "Hoge"
val s2 : String = "Bar"
System.out.println(new Sample1[String](s1).compare(s2))
System.out.println(new Sample2[String](s1).compare(s2)) // 'Implicit conversions found: s1 => augmentString(s1)'
}
}
class Sample1[K](val k : Comparable[K]) {
def compare(k2 : K) : Int = {
System.out.println("Sample1 type of k: " + k.getClass().getName())
return k.compareTo(k2)
}
}
class Sample2[K](val k : Ordered[K]) {
def compare(k2 : K) : Int = {
System.out.println("Sample2 type of k: " + k.getClass().getName())
return k.compareTo(k2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment