<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國際加速解決方案。 廣告
                基本語法: ```scala // [ ] 符號表示可選 // 如果省略返回值不寫,則稱為過程 def funName([參數列表]):[返回值]= { // 函數體 return [表達式] ``` ```scala /*********** 1. 標準寫法 ************/ def square(x:Int):Int = { println(x) x * x // 這就是返回值 } /*********** 2. 不寫返回類型,Scala編譯器會自動判斷 ************/ def square(x:Int) = { println(x) x * x } /*********** 3. 自動返回 Unit *************/ def sayHello(x:String):Unit={ println("hello") // 默認會自動調用 return () 來返回 () } /*********** 4. 無返回值的寫法 ************/ // 如果省略 = ,則什么都不返回,即使是 () 也不返回 def sayHello(x:String){ println(x)} /********** 5. 傳值調用寫法 *************/ def square(x:Int):Int = { println(x) x * x } square(1+2) // 先計算1+2,再計算 3 * 3 /********** 6. 傳名調用的寫法 *****************/ def square(x:=>Int):Int={ println(x) x*x } square(1+2) // 先不計算,在函數體中用到時才開始計算 /******** 7. 命名參數的寫法 ****************/ def printName(first:String, last:String) = { println(first + ", " + last) } printName("First", "Last") printName(first="First", last="Last") /************ 8. 參數缺省值的寫法 ***********/ def printName(first:String="First", last:String="Last")={ println(first + "," + last) } printName() // First,Last printName("John") // John,Last printName("John", "Tom") // John,Tom printName(last="Tom") // First,Tom /************* 9. 匿名函數的寫法 **************/ // (參數列表) => {函數體} (x:Int) => x*x (x:Int) => {println(x); x*x} () => {println("Hello)} val fun1 = (x:Int) => {println(x); x*x} fun1(2) ```
                  <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>

                              哎呀哎呀视频在线观看