That's up to the ECMAScxript committee. But since I think an Adobe engineer chairs or co-chairs it, we have some influence.
- Gordon ________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of Ralf Bokelberg Sent: Wednesday, February 07, 2007 11:10 AM To: flexcoders@yahoogroups.com Subject: Re: [flexcoders] Returning 'this' from an overridden method? Nice to know the name of this feature. Just lately somebody asked me the same question. He also came from a Java background. Any chance we will see it in the future? Cheers, Ralf. On 2/7/07, Sho Kuwamoto <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > wrote: The short answer is that there is no way to do what you want for the time being. What you are looking for is a language feature called "covariant return types". In certain languages (C++, Java) you can have your subclass redefine the type that is returned by a method. This would be a great thing to get into the AS language, but it is not there now. There are further wrinkles when you consider how you would extend properties in a similar way (I wrote about the issues at http://kuwamoto.org/2007/01/22/covariant-property-types/ <http://kuwamoto.org/2007/01/22/covariant-property-types/> ). Cheers, -Sho ________________________________ From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com <http://yahoogroups.com> ] On Behalf Of David_Stafford Sent: Tuesday, February 06, 2007 6:13 PM To: flexcoders@yahoogroups.com Subject: [flexcoders] Returning 'this' from an overridden method? Please pardon this simple-minded question from an AS3 novice. My base class often returns 'this' from methods which makes it convenient to write code like: camera.move( 10, 12 ).rotateX( 45 ).rotateY( 90 ); The problem comes when code extends the base class and overrides one of these functions. The compiler insists, correctly, that the return type of an overriding function must match the one in the base class. What I want to do is return the 'this' object that is of the type of the derived class. Is this possible? The following is a contrived example to demonstrate. It won't compile because the overridden function in the derived class wants to return a type of MyCamera rather than Camera: public class Camera { var x:int = 0; var y:int = 0; public function move( x:int, y:int ) :Camera { this.x += x; this.y += y; return( this ); } } public class MyCamera extends Camera { override public function move( x:int, y:int ) :MyCamera { super.move( x, y ); if( x < 0 ) x = 0; if( y < 0 ) y = 0; return( this ); } } -- Ralf Bokelberg <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > Flex & Flash Consultant based in Cologne/Germany Phone +49 (0) 221 530 15 35