Created
July 16, 2012 13:29
-
-
Save masayuki038/3122729 to your computer and use it in GitHub Desktop.
Ordered[A] and Comparable[A]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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