scala 隐式转换

https://blog.csdn.net/bluishglc/article/details/50866314
https://www.jianshu.com/p/3f8289b07477
https://blog.csdn.net/zhanglh046/article/details/72845897

scala 泛型
[T <% ViewBound]
视图边界

[T : ContextBound]
上下文边界

trait Ordered[A] extends Any with java.lang.Comparable[A] {

  /** Result of comparing `this` with operand `that`.
   *
   * Implement this method to determine how instances of A will be sorted.
   *
   * Returns `x` where:
   *
   *   - `x < 0` when `this < that`
   *
   *   - `x == 0` when `this == that`
   *
   *   - `x > 0` when  `this > that`
   *
   */
  def compare(that: A): Int

  /** Returns true if `this` is less than `that`
    */
  def <  (that: A): Boolean = (this compare that) <  0

  /** Returns true if `this` is greater than `that`.
    */
  def >  (that: A): Boolean = (this compare that) >  0

  /** Returns true if `this` is less than or equal to `that`.
    */
  def <= (that: A): Boolean = (this compare that) <= 0

  /** Returns true if `this` is greater than or equal to `that`.
    */
  def >= (that: A): Boolean = (this compare that) >= 0

  /** Result of comparing `this` with operand `that`.
    */
  def compareTo(that: A): Int = compare(that)
}

object Ordered {
  /** Lens from `Ordering[T]` to `Ordered[T]` */
  implicit def orderingToOrdered[T](x: T)(implicit ord: Ordering[T]): Ordered[T] =
    new Ordered[T] { def compare(that: T): Int = ord.compare(x, that) }
}
final class RichInt(val self: Int) extends AnyVal with ScalaNumberProxy[Int] with RangedProxy[Int] {
    ......
}
trait ScalaNumberProxy[T] extends Any with ScalaNumericAnyConversions with Typed[T] with OrderedProxy[T] {
    ...
    trait OrderedProxy[T] extends Any with Ordered[T] with Typed[T] {
        protected def ord: Ordering[T]

        def compare(y: T) = ord.compare(self, y)
    }
    ...
}
trait Ordered[A] extends Any with java.lang.Comparable[A] {
    ...
}
trait Ordering[T] extends Comparator[T] with PartialOrdering[T] with Serializable {
    ...
}

你可能感兴趣的:(scala 隐式转换)