Kotlin generic variance modifiers finally made sim...
# feed
m
Kotlin generic variance modifiers finally made simple! https://blog.kotlin-academy.com/kotlin-generics-variance-modifiers-36b82c7caa39
s
List interface has covariant type parameter, because it is immutable
List interface is readonly and it is not the same as immutable, no?
v
👆
m
@snrostov AFAIU, immutability is a far stronger guarantee than being readonly. You can have a collection interface, which provides a readonly view to some other collection. This means that you cannot change the underlying data through a reference to that particular interface, but that provides absolutely no guarantee that there isn't some read-write reference to the same data somewhere else which could allow it to change right from under you. Would that mean, that interfaces can be readonly, but only concrete classes can be truly immutable (reflection doesn't count)? Maybe. Or I could have all of this mixed up.
m
It is common figure of speech to say that Kotlin List is immutable and I think that it is more understandable this way.
r
Frankly the distinction between immutable and read-only isn't as clear cut as many people seem to believe. @matej Many people have different ideas about what the distinction is, including (but not limited to) the one you presented, but there isn't any commonly accepted or standardized definition. (There's a similar issue with what "coroutine" means, leading to many arguments about whether Kotlin's coroutines are "true" coroutines.)
👍 1
m
@Ruckus You're right, there's a lot of nuance to be found on that topic.
👍 2
s
@marcinmoskala thanks for the article I definitely went one step further on generics. I'm a bit puzzled finding this kind of generics :
val listOf: List<ErrorDispatcher<{T & OutputWithNetworkError}>>
have you encountered any documentation around those
👍 1
m
Where did you found this and does it work? It looks like type union, which I would love to heve in Kotlin but as far as I know is not implemented yet. Here is example in Ceylon: https://ceylon-lang.org/documentation/reference/structure/type/