Kotlin Upper Bound: What Difference Does `:any` Make To Kotlin's Generic Type Inference?
Following the Kotlin for Android Developers book, we come across extension function fun SelectQueryBuilder.parseList(parser: (Map) -> T):List<
Solution 1:
Now, as far as I'm concerned,
Tshould implyT:Any
T implies T:Any?, where Any? is the closest equivalent to Java's Object. With T:Any you specified a non-nullable type.
Solution 2:
The :Any defines an upper bound for your generic type argument. As you can read in the Generics: Upper Bounds chapter of the Kotlin documentation, the default upper bound is Any?:
The default upper bound (if none specified) is
Any?
Thus, <T> is equivalent to <T: Any?>
Post a Comment for "Kotlin Upper Bound: What Difference Does `:any` Make To Kotlin's Generic Type Inference?"