Actionscript overriding methods in extended interfaces vs Java?

In AS3, method signatures must be identical in both implementation and inheritance, so if you define the return type of makeCopy as Ia initially, that's how it must stay in all descendant interfaces and implementations thereof What you can do however, is return an instance of an object that implements Ib through a function signed with Ia because it will still be a valid implementation of Ia : public class B implements Ib { public function makeCopy():Ia { return this; } public function B() { trace(makeCopy() is Ia); //true trace(makeCopy() is Ib); //true trace(makeCopy() is B); //true } }.

In AS3, method signatures must be identical in both implementation and inheritance, so if you define the return type of makeCopy as Ia initially, that's how it must stay in all descendant interfaces and implementations thereof. What you can do however, is return an instance of an object that implements Ib through a function signed with Ia, because it will still be a valid implementation of Ia: public class B implements Ib { public function makeCopy():Ia { return this; } public function B() { trace(makeCopy() is Ia); //true trace(makeCopy() is Ib); //true trace(makeCopy() is B); //true } }.

Shane - your solution works, but I am very desirous to keep the types as specific as possible. But your answer got me thinking that I could modify the code generation of the higher-level actionScript interfaces to not include these methods...thus demoting them to marker interfaces. Neither solution is ideal, but something has to give.... – HDave Oct 21 at 13:14.

From the context of ActionScript, the return type of makeCopy() has an incompatible signature. Interface Ia defines makeCopy returning Ia. Interface Ib extension would return Ia base from makeCopy.

Adding makecopy():Ib to interface Ib is an incompatible override to the definition in Ia. In class B, the incompatible signature expects makeCopy to return Ia. Perhaps what you're trying to accomplish is more like an Abstract Class, where you should extend A and B classes.

I think this means that changing the signature to return a subtype of the originally specified type won't work. – HDave Oct 20 at 15:59.

MakeCopy()" on the interface returns an Ia. Whereas in the implementation it returns an Ib. Unless an Ib is an Ia it is going to fail.

I agree, except that Ib IS an Ia -- so it would never fail. – HDave Oct 20 at 15:53 @HDave Ib is NOT an Ia. (Ib==Ia)=false; Ib extends Ia which means Ib also inherits makeCopy().

It still will return Ia – The_asMan Oct 20 at 17:13 Anything that implements Ib adheres to the contract of Ia. Thats why this compiles and runs fine in Java. – HDave Oct 20 at 20:42 @HDave Do Ia and Ib extend an abstract class on the Java side?

– FlexFiend Oct 21 at 13:01 No...the code in Java is just as it appears in Actionscript and compiles and runs fine. Also, my saying that Ib "is a" Ia did not mean equal, it meant "is a". See my comment up above...if I were to modify the overridden method to return an "int" then Java won't compile because int "is not a" Ia, but Ib "is a" Ia so it works in Java.

Just wish it did in Actionscript too. – HDave Oct 21 at 13:17.

In AS3, method signatures must be identical in both implementation and inheritance, so if you define the return type of makeCopy as Ia initially, that's how it must stay in all descendant interfaces and implementations thereof.

From the context of ActionScript, the return type of makeCopy() has an incompatible signature.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions