fun <Comparable<T>> foo(a: T) {}
won't compile. The bit inside the
<...>
has to be a valid type variable name, and
Comparable<T>
isn't a valid name because it contains
<
and
>
.
In
fun <T : Comparable<T>> foo(a: T) {}
you are declaring a type variable
T
, and then saying that whatever
T
actually ends up being at runtime, it
must be a subtype of
Comparable<T>
. So you will be able to call
a.compareTo(TODO())
inside that method.
Where as in
fun <T> foo(a: T) {}
,
T
could be any type at runtime