HaxeDoc2

(やまだぃちぅ) #1
Ais abstract

AdefinestoforB

Bis abstract

BdefinesfromforA

Unification fails

No

Yes

No

Yes

Unification succeeds

No

No

Yes

Yes

Figure 2.1: Selection algorithm flow chart.

7 public function new() this = 0;
8 @:to public function toC() returnnew C();
9 }
10
11 abstract C(Int){
12 public function new() this = 0;
13 }
14
15 class Main {
16 static public function main() {
17 var a = new A();
18 var b:B = a; // valid, uses A.toB
19 var c:C = b; // valid, uses B.toC
20 var c:C = a; // error, A shouldbe C
21 }
22 }


While the individual casts fromAtoBand fromBtoCare allowed, a transitive cast fromAtoC
is not. This is to avoid ambiguous cast-paths and retain a simple selection algorithm.

2.8.2 Operator Overloading


Abstracts allow overloading of unary and binary operators by adding the@:opmetadata to class
fields:
1 abstract MyAbstract(String){
2 public inline function new(s:String){
3 this = s;
4 }
Free download pdf