Re: Covariant Return Types
Arjan Boeijink <[email protected]> Wed, 25 Feb 2004 03:03:01 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
>Okay, but try this version:
>
> package c;
> interface A { }
> interface B { }
> A doSomething(A a) { ... }
> B doSomething(B b) { ... }
>
> package d;
> import c;
> class C implements A, B { }
> override c.doSomething(C a) { ... }
>
>Now, does d.doSomething(C) override c.doSomething(A) or c.doSomething(B)? Notice
>in the old specialization syntax, the last line would be:
> override c.doSomething(a@C);
>And then, we could generalize the syntax to:
> override c.doSomething(A a@C);
>which would make it obvious that we are specializing c.doSomething(A).
For ambiguities of which method to implementation belong to can be solved using an additional type (the compiler has support for this a long time)
doSomething(C(A) a) { ...} //add implementation for doSomething(A)
doSomething(C(B) a) { ... } //add implementation for doSomething(B)
>Also, notice that when the package name is long, it is ugly to provide many
>specializations using that syntax.
True but you can use the additional type construct in most cases.
Arjan
-------------------------------------------------------
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