https://kotlinlang.org logo
c

CLOVIS

09/09/2020, 9:50 AM
How can I write “this function accepts a parameter that should implement both Comparable and Serializable” (or any other two interfaces). I know I can define a generic as
<T: out Comparable>
to get the first one, but I don't see how to have two constraints.
j

Jordan Stewart

09/09/2020, 9:57 AM
you can use
where
(https://kotlinlang.org/docs/reference/generics.html#upper-bounds) e.g.
fun <T> test(t: T) where T : Comparable<T>, T : Serializable
👍 2
c

CLOVIS

09/09/2020, 3:51 PM
Wow, that's amazing, thanks!