[swift-evolution] [Manifesto] Completing Generics

Howard Lovatt howard.lovatt at gmail.com
Thu Mar 10 15:59:13 CST 2016


@Joe,

Yes; but casts can fails in most languages, e.g.:

func foo() -> Any {
    return 0;
}

let f = foo() as! Float


  -- Howard.

On 11 March 2016 at 08:37, Joe Groff <jgroff at apple.com> wrote:

>
> 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/20160311/79fb34e5/attachment.html>


More information about the swift-evolution mailing list