hudsonb
11/29/2018, 1:44 PMreified R
I would like to return a default comparator to use based on `R`s type. Is there any way to do something like this?
inline fun <reified R> defaultComparator(): Comparator<R>? = when {
R::class.isSubclassOf(Comparable::class) -> naturalOrder<R>() // Error: Type arg not within bounds
// ... others
else -> null
}
diesieben07
11/29/2018, 1:47 PMhudsonb
11/29/2018, 1:51 PMnaturalOrder
expects a Comparable<R>
but AFAIK there's no way to indicate that R
is Comparable<R>
?diesieben07
11/29/2018, 1:53 PMnaturalOrder<Nothing>() as Comparator<R>
hudsonb
11/29/2018, 1:58 PMdiesieben07
11/29/2018, 1:59 PMNothing
is a great tool if you're trying to fight the type system 😄Katya Yurukova
11/29/2018, 2:04 PMhudsonb
11/29/2018, 4:04 PMR
is not Comparable<R>
.