开发者

Ambiguous reference when getter/setter have different visibilities

开发者 https://www.devze.com 2022-12-23 20:45 出处:网络
The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite;

The following code raises an ambiguous reference to value at compile time:

import flash.display.Sprite;

publi开发者_如何学Cc class Main extends Sprite
{
    private var _value : Number = 0.;

    public  function get value() : Number           { return _value; }
    private function set value(v : Number) : void   { _value = v; }

    public function Main() : void
    {
        value = 42.;
    }
}

I suspect some kind of bug in the compiler, though I didn't actually read the ECMA standard.

Before someone asks those questions:

  • Private setters do make sense.
  • The ambiguity also exists with custom namespaces (which is the problem I'm facing).


it is indeed a bug in the compiler, and it is listed in the bugs. its stated that its an oversite of the developers and wont be fixed any time soon.

if you are needing to specifically run a function to set privately (rather than just assign the value, in which case you can leave out the setter function completely and itll run) then you will have to run a seperate function as Sandro said.


I think this may be a limitation of AS3. You could create a private function called setValue() or if your set on having a setter you might be able to get away with this, although it's not very pretty.

package {
    import flash.display.Sprite;

    public class Main extends Sprite {
        private var __value :Number = 0;

        public function Main(): void {
            _value = 42;
        }
        public function get value():Number {
            return __value;
        }
        private function set _value(v:Number):void {
            __value = v;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消