[swift-evolution] [Manifesto] Completing Generics
Joe Groff
jgroff at apple.com
Thu Mar 10 15:37:35 CST 2016
> On Mar 10, 2016, at 1:34 PM, Howard Lovatt <howard.lovatt at gmail.com> wrote:
>
> @Thorsten,
>
> No it doesn't, the following Java code:
>
> public class GenericReturnTypes {
> interface Foo {
> static <Output extends Number> Output foo() {
> return (Output)(new Integer(0));
> }
> }
> public static void main(String[] args) {
> System.out.println(Foo.foo());
> }
> }
>
> Compiles without error or warning, runs, and prints 0.
This works by inferring Output == Number. This also unsafely allows 'Float foo = Foo.foo();', which would fail the cast.
-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160310/53db4912/attachment.html>
More information about the swift-evolution
mailing list