Just out of interest - back in the days when Kotlin was first designed was there any discussion about making covariant generic types the default, with invariant & contravariant requiring extra syntax? My gut feel is that most people expect
Foo<String>
to be a subtype of
Foo<Any>
, and if you favour immutable data types then covariance often Just Works™.
I try and remember to use
<out T>
as my starting point, until I need something else, but I often forget...
e
ephemient
01/06/2022, 9:06 PM
I don't know, but defaulting to
<out T>
only makes sense for immutable types
r
Rob Elliot
01/07/2022, 9:27 AM
Yup, but I think there's a case, in the spirit of nudge, for biasing the language towards immutable types.