Re: Covariant Return Types
Daniel Bonniot <[email protected]> Fri, 05 Mar 2004 01:12:28 +0100
| Newsgroups | gmane.comp.lang.nice.general |
|---|---|
| Message-ID | <[email protected]> |
[email protected] wrote: >Quoting Daniel Bonniot <[email protected]>: > > > >>> package a; >>> class A { } >>> class B extends A { } >>> A self(A a) = a; >>> B self(B b) overrides A self(A) = b; >>> >>> void main(String [] args) { >>> let x = self(A); // syntax? >>> let y = self(B); // syntax? >>> println(x == y); >>> } >>> >>>Do I get "true" or "false"? >>> >>> >>> >>You get: "A is not a value" a the first line with the comment :-) >> >>What do you mean? self(new A()) ? >> >> > >I mean, "let x be a reference to the method with type A -> A" and "let y be a >reference to the method with type B -> B." > > OK, then there is no need for specific syntax. You could write anonymous functions (the eta-long form in lambda calculs) to disambiguate: let x = A a => self(a); let y = B b => self(b); and x == y will be false. But comparing the identity of anonymous functions is not a very good idea in any case. Daniel ------------------------------------------------------- This SF.Net email is sponsored by: IBM Linux Tutorials Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click