In Kotlin, what is there difference between the following two functions:
fun<T> List<T>.myFunction() { ...
fun<T : Any> List<T>.myOtherFunction() { ...
Presumably this Any
constraint is there for a reason, but what is it?
<T>
: Without any constraints, it can be any type, including nullable types (e.g., T?), platform types, and non-nullable types
<T : Any>
: Must be a non-nullable type. It excludes nullable types and platform types, ensuring that T is a concrete, non-nullable type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With