actionscript 3 - How do I return different type from overridden method? -
i'm extending as3 class rectangle class called bin. want override rectangle clone() method method returns bin object, not rectangle object. if try override clone method specify bin return type, #1023: incompatible override error. here's bin class:
package { import flash.geom.rectangle; public class bin extends rectangle { public function bin(x:number = 0, y:number = 0, width:number = 0, height:number = 0) { super(x, y, width, height); } override public function clone():rectangle { return new bin(x, y, width, height); } } }
this class works, when use clone() method create new bin instance, type errors when try use bin methods on new instance.
how override clone() , send actual bin instance?
technically, can't change signature when override method. in case, though, not huge problem. have cast resulting object type bin after calling clone method.
Comments
Post a Comment