[swift-evolution] Make generics covariant and add generics to protocols
david at alkaline-solutions.com
Tue Jan 12 20:07:51 CST 2016
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.
> On Jan 12, 2016, at 6:47 PM, Howard Lovatt via swift-evolution <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...
More information about the swift-evolution