HaxeDoc2

(やまだぃちぅ) #1

4
5 class Main extends Base {
6 // ok, get_x is declared by parentclass
7 public var x(get, null):Int;
8
9 static public function main() {}
10 }


Thedynamicaccess modifier works exactly likegetorset, but does not check for the
existence

4.2.3 Rules for getter and setter


Visibility of accessor methods has no effect on the accessibility of its property. That is, if a prop-
erty ispublicand defined to have a getter, that getter may me defined asprivateregardless.
Both getter and setter may access their physical field for data storage. The compiler ensures
that this kind of field access does not go through the accessor method if made from within the
accessor method itself, thus avoiding infinite recursion:
1 class Main {
2 public var x(default, set):Int;
3
4 function set_x(newX){
5 return x = newX;
6 }
7
8 static public function main() {}
9 }
However, the compiler assumes that a physical field exists only if at least one of the access
identifiers isdefaultornull.

Definition: Physical field
A field is considered to bephysicalif it is either


  • a variable (4.1)

  • a property (4.2) with the read-access or write-access identifier beingdefaultornull

  • a property (4.2) with:isVarmetadata (6.9)


If this is not the case, access to the field from within an accessor method causes a compilation
error:
1 class Main {
2 // This field cannot be accessedbecause it
3 // is not a real variable
4 public var x(get, set):Int;
5
6 function get_x() {
7 return x;
8 }
9
Free download pdf