4
extends Comparable[A]
을 extends Ordered[A]
으로 변경하고 def compareTo
을 def compare
으로 충분히 이름을 바꿉니 까 무엇이 있습니까?java.lang.Comparable을 구현하는 클래스를 변환하여 Scala.Ordered를 구현하는 방법?
extends Comparable[A]
을 extends Ordered[A]
으로 변경하고 def compareTo
을 def compare
으로 충분히 이름을 바꿉니 까 무엇이 있습니까?java.lang.Comparable을 구현하는 클래스를 변환하여 Scala.Ordered를 구현하는 방법?
정확합니다. 그게 전부입니다. 로 이동 기본 구현을 사용합니다 Ordered
의 다른 방법은 다음과 같습니다
def < (that: A): Boolean = (this compare that) < 0
def > (that: A): Boolean = (this compare that) > 0
def <= (that: A): Boolean = (this compare that) <= 0
def >= (that: A): Boolean = (this compare that) >= 0
def compareTo(that: A): Int = compare(that)
당신이 이전 compareTo
방법을 사용하여 정의됩니다 Ordered
의 기본 구현이 비교되어이없는 유일한 것은, . 위의 내용이 다른 비교를 위해 원하는 경우 작동해야합니다.
감사합니다. – soc