Re: Covariant Return Types
Daniel Bonniot <[email protected]> Wed, 25 Feb 2004 02:25:32 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>> override merge(parent, TextElement left, TextElement right) = ...
>>
>>
>
>I don't think this works in general, when =merge= is overloaded already.
>
This is not specific to this proposal. Currently, when implementing a
method which has synonyms (other methods of the same name), you
sometimes need to disambiguate which one you mean to implement. There
are ways to do that (adding patterns, and the additional types between
brackets).
>>(BTW, this example is not covariant so it's unsafe. First fromString
>>says: I can return you anything you want (if I return!). Then the
>>implementation does not return anything the client wants, it returns an A.)
>>
>>
>
>You always catch these. :)
>
I must have a type-checker built-in or something ;-)
>Try:
>
> public A fromString(String s) { throw new Error(); }
> A fromString("a") = new A();
> B fromString("b") = new B();
>
>
Correct, that's covariant.
>But, I think we all agree that this is not something worth allowing.
>
>
OK.
Daniel
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click