<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] ## 重寫類的成員 子類可以覆蓋實例方法、getter和setter。您可以使用@override注釋來指示你重寫了某個成員方法: ~~~ class SmartTelevision extends Television { @override void turnOn() {...} // ··· } ~~~ 要在類型安全的代碼中縮小方法參數或實例變量的類型,可以使用covariant關鍵字。 ## 重寫操作符 您可以重寫下表中顯示的操作符。例如,如果定義一個Vector類,可以定義一個+方法來讓兩個向量相加。 | < | + | \| | [] | | --- | --- | --- | --- | | > | / | ^ | []= | | <= | ~/ | & | ~ | | >= | * | << | == | | - | % | >> | | 下例在類中重寫了+和-操作符: ~~~ class Vector { final int x, y; Vector(this.x, this.y); Vector operator +(Vector v) => Vector(x + v.x, y + v.y); Vector operator -(Vector v) => Vector(x - v.x, y - v.y); // Operator == and hashCode not shown. For details, see note below. // ··· } void main() { final v = Vector(2, 3); final w = Vector(2, 2); assert(v + w == Vector(4, 5)); assert(v - w == Vector(0, 1)); } ~~~ 如果重寫==,還應該重寫對象的hashCode getter。有關override == 和hashCode的示例,請參見[ Implementing map keys]。 有關重寫的更多信息,請參見[擴展類]。 ## noSuchMethod() 可以重寫noSuchMethod()方法來處理程序訪問一個不存在的方法或者成員變量: ~~~ class A { // Unless you override noSuchMethod, using a // non-existent member results in a NoSuchMethodError. @override void noSuchMethod(Invocation invocation) { print('You tried to use a non-existent member: ' + '${invocation.memberName}'); } } ~~~ 您不能調用未實現的方法,除非下列任何一個是正確的: * 被調用者有靜態方法dynamic * 被調用者有一個靜態類型來定義未實現的方法(抽象也可以OK),而接收者的動態類型有一個noSuchMethod()的實現,它與類對象中的方法不同。 更多信息,請參見[noSuchMethod轉發規范]
                  <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>

                              哎呀哎呀视频在线观看