<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                抽象類型通過添加 `@:op` 元數據到類字段,允許一元和二元運算符的重載: ~~~ abstract MyAbstract(String) { public inline function new(s:String) { this = s; } @:op(A * B) public function repeat(rhs:Int):MyAbstract { var s:StringBuf = new StringBuf(); for (i in 0...rhs) s.add(this); return new MyAbstract(s.toString()); } } class Main { static public function main() { var a = new MyAbstract("foo"); trace(a * 3); // foofoofoo } } ~~~ 通過默認的 `@:op(A*B)`,當左面的值類型是 `MyAbstract` 而且右側值是 Int 類型的時候,函數 `repeat` 作為乘法 `*` 運算符的運算符。用法在第17行顯示,編譯到 JavaScript 之后代碼成為這樣: ~~~ console.log(_AbstractOperatorOverload.MyAbstract_Impl_.repeat(a,3)); ~~~ 類似于通過 [類字段(第2.8.1)](http://#) 方式隱式轉換,重載之后的方法的調用被插入到需要的地方。 示例中的 `repeat` 函數是不可交換的:當 `MyAbstract * Int` 工作,`Int * MyAbstract` 則不工作。如果這應該同時允許,可以添加` @:commutative` 元數據。如果它只可以為 `Int * MyAbstract` 工作,而不是為 `MyAbstract * Int`,重載方法可以被設置為 `static`,接受 Int 和 MyAbstract 分別作為第一個和第二個類型。 重載一元運算符是相似的: ~~~ abstract MyAbstract(String) { public inline function new(s:String) { this = s; } @:op(++A) public function pre() return "pre" + this; @:op(A++) public function post() return this + "post"; } class Main { static public function main() { var a = new MyAbstract("foo"); trace(++a); // prefoo trace(a++); // foopost } } ~~~ 二元運算和一元運算符重載都可以返回任何類型。 **暴露潛在類型的操作** 還可以省略 `@:op` 函數的方法體,但是只有抽象類型的潛在類型允許涉及的操作,并且結果類型可以被賦值回抽象類型的時候。 ~~~ abstract MyAbstractInt(Int) from Int to Int { // 下面一行從潛在類型Int暴露 (A>B)操作符 // 注意,并沒有使用函數體 @:op(A > B) static function gt( a:MyAbstractInt, b:MyAbstractInt ) : Bool; } class Main { static function main() { var a:MyAbstractInt = 42; if(a > 0) trace(’Works fine, > operation implemented!’); // 小于操作符沒有實現 // 這會引起一個 “不能對比MyAbstractInt 和 Int”的錯誤: if(a < 100) { } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看