雲星數據---Scala實戰系列(精品版)】:Scala入門教程053-Scala實戰源碼-Scala implicit 操作04

Scala implicit 操作04

package scala_learn.demo12_Implicit

/**
 * Created by liguohua on 2017/3/1.
 */
class O5_ImplicitDemo {

}

object O5_ImplicitDemo {
  def main(args: Array[String]) {
    val rs = 0.incr(3)
    println(rs)
  }

  //隱式類不能是頂層類
  implicit class Caculate(i: Int) {
    //定義一個增強方法
    def incr(i: Int): Int = i + 1
  }

  implicit class Pow(g: GrandF) {
    def pow(): Unit ={
      println("get power")
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章