AS3: Impossible to have getters and setters for one variable in different interfaces?

The following code seems to create ambiguity for the compiler (see the missing error below). Is it not possible to separate getters and setters between interfaces?

public interface GetterInterface 
{
    function get test():int;
}

public interface SetterInterface 
{
    function set test(value:int):void;
}

public interface SplitTestInterface extends GetterInterface, SetterInterface
{

}

public class SplitTest implements SplitTestInterface
{

    public function SplitTest() 
    {

    }

    /* INTERFACE test.SetterInterface */

    public function set test(value:int):void 
    {

    }

    /* INTERFACE test.GetterInterface */

    public function get test():int 
    {
        return 0;
    }

}

//Somewhere...
var splitTest:SplitTestInterface = new SplitTest();
splitTest.test = 2; //Error: Property is read-only.
+3
source share
2 answers

I have compiled the following (which is almost identical to your code) and works fine for the get and set method.

/* IGet.as */
package {
    public interface IGet 
    {
        function get test():int;
    }
}


/* ISet.as */
package {
    public interface ISet 
    {
        function set test(i:int):void;
    }
}


/* ISplit.as */
package {
    public interface ISplit extends IGet, ISet {
    }
}

/* SplitTest.as */
package {
    public class SplitTest implements ISplit {

        public function SplitTest() {
        }

        public function set test(i:int):void {
            trace("Set");
        }

        public function get test():int {
            trace("Get");
        }
    }
}

The following is shown on the main line:

var foo:SplitTest = new SplitTest();
foo.test;
foo.test = 1;

And outputs:

Get
Set
+2
source

Interest Ask. Based on the output, it seems that the compiler really does not understand what is happening. Using a native compiler to force a call, a call in the player results in

Property SplitTestInterface::test not found on SplitTest and there is no default value.

, - . . , .

: , .

-1

Source: https://habr.com/ru/post/1794782/


All Articles