[swift-evolution] Make generics covariant and add generics to protocols

Simon Pilkington simonmpilkington at icloud.com
Tue Jan 12 21:08:10 CST 2016

What uses do you see for covariance defined by the author of a type?

Also I agree with you about Java; in particular for me the combination of covariance, Raw Types and Type Erasure create a very confusing system which sometimes seems to be of little benefit.


> On 13 Jan 2016, at 1:07 PM, David Waite <david at alkaline-solutions.com> wrote:
> Java only has invariance at the generic type definition level. They allow you to use wildcards as another option to generic constraints for instance references. In effect, variance is faked by the user of a type, not defined by the author of the type.
> The dynamic and unreified nature of java generics is such that several valid systems I have encountered are impossible to properly express. Likewise, several systems I have tried to debug using generics have been found to have unsound generic type systems due to the language not enforcing proper static typing.
> IMHO Java is not a good language to use as an example when trying to make a case for changing the behavior of generics.
> -DW
>> On Jan 12, 2016, at 6:47 PM, Howard Lovatt via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> Yes you can annotate for covariance, invariance, and contravariance, both Java and Scala, allow all three. The problem is that the code becomes splattered with variance annotations. The Java people themselves have publicly regretted this and wished that they had made covariance the default. If you look at generic code invariance and covariance are by far the most common requirements; this proposal would address these common use case without burdening the programmer.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160113/dc8c3aac/attachment.html>

More information about the swift-evolution mailing list