5 ms·
That’s cool! Thanks for sharing, I had never considered that aspect of private[this]. Mentioned in the article, but it also powers covariant classes. In a lang
by jez 3y ago
That’s cool! Thanks for sharing, I had never considered that aspect of private[this].
Mentioned in the article, but it also powers covariant classes. In a language like C# only interfaces can have covariant type parameters, because it wouldn’t be sound to store a value in a (C#) private field if it had a covariant type. This influences a lot of the API design in C# where basically every container a covariant/immutable interface alongside the invariant/mutable implementation.
(Java gets around this with use site variance annotations which are more flexible but have their own drawbacks).