Unlike Ordering[String]
or Ordering[Int]
, Scala doesn't have an explicit val
or object
with Ordering[Instant]
. Scala compiler generates one on demand when you implicitly request it by relying on the fact that Instant
extends Comparable
in Java.
If you want to use the Ordering[Instant]
provided by Scala, you have to summon the implicit one and have the compiler generate it for you:
MyRuleEngine(rule).eval(instant1, instant2)(Ordering[Instant])
or
MyRuleEngine(rule).eval(instant1, instant2)(implicitly)
You may also manually create an Ordering[Instant]
in the same way the compiler does:
MyRuleEngine(rule).eval(instant1, instant2)(Ordering.ordered(identity))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…