scala 隐式转换(6

21 阅读1分钟
package imp

import scala.language.postfixOps

object imp07 {
  implicit class StrongInt(n:Int) {
    def !() : Int = {
     // println("阶乘......")
      var s = 1
      for (i <- 1 to n){
        s *= i
      }
      s
    }
  }

    def main(args: Array[String]): Unit = {
      var k = 10;
      //计算k的阶乘
      printf(s"${k}的阶乘是:${k!}")
    }
}