-
-
Notifications
You must be signed in to change notification settings - Fork 143
Open
Description
This code doesn't compile with the latest builds of JDK 26:
Lines 31 to 34 in 3bdeb08
new Ordering[T] { | |
def compare(x: T, y: T): Int = { | |
x.asInstanceOf[Comparable[T]].compareTo(y) | |
} |
A recent JDK change JDK-8357219: Provide default methods min(T, T) and max(T, T) in Comparator interface adds default methods named min
and max
to the Comparator
interface, which clash with existing methods inherited in Ordering
, and cause the following error:
com/fasterxml/jackson/module/scala/introspect/OrderingLocator.scala:31: error: <$anon: Ordering[T]> inherits conflicting members:
<defaultmethod> def max[U <: T](o1: U, o2: U): U (defined in trait Comparator) and
def max[U <: T](x: U, y: U): U (defined in trait Ordering)
(note: this can be resolved by declaring an `override` in <$anon: Ordering[T]>.);
other members with override errors are: min
new Ordering[T] {
^
1 error
One possible fix is to explicitly declare min
and max
methods in the Ordering
implementation, with the same behaviour as the conflicting inherited methods:
new Ordering[T] {
+ override def min[U <: T](x: U, y: U): U = if (compare(x, y) < 0) x else y
+ override def max[U <: T](x: U, y: U): U = if (compare(x, y) > 0) x else y
def compare(x: T, y: T): Int = {
x.asInstanceOf[Comparable[T]].compareTo(y)
}
}
Metadata
Metadata
Assignees
Labels
No labels