1 Reply Latest reply on May 21, 2007 1:10 AM by jpwrunyan

    Different access modifiers for get vs. set

      Does anyone know why using different access modifiers on getters and setters would cause an ambiguous reference error? In java this isn't an issue, however it seems to be a problem when attempting to create publicly available properties where it is only internally modifiable by certain objects. As a last resort I could restrict it to read-only access with internal methods, but that wasn't the point in creating property access.

      Example (in pseudo code):
      package a:
      class a:
      public get owner():Object
      internal set owner(o:Object):void { ..do stuff }

      package a:
      class b:
      public function createWidget(obj:a) {
      a.owner =this; //Error: Ambiguous reference to owner.

      package b:
      var x =new b();
      x.createWidget(new a());
        • 1. Re: Different access modifiers for get vs. set
          jpwrunyan Level 1
          "get/set property"
          and "getProperty()/setProperty()" are completely different.
          get/set is supposed to act like a property so the access modifier needs to be identical. There are other such limitations to guarantee that get/set behaves as a regular var property.
          For anything else you really need to use regular java-like getter/setter methods (ie, actual methods... not the psuedo property get/set syntax).