欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Scala 链式

最编程 2024-10-18 07:06:40
...
链式风格:在方法中返回当前对象!

对象,方法1().方法2().方法3().方法3()
args.map().foreach().toString
class Stu11{
  //this.type就是当前这个方法的返回值类型
  def say(): this.type = {
    println("say.....")
    this//当前对象
  }
  def run(): this.type = {
    println("run.....")
    this
  }
  def sleep(): this.type = {
    println("sleep.....")
    this
  }
}
object Test1111 {
  def main(args: Array[String]): Unit = {
    val s1=new Stu11
    s1.say().run().sleep()
    }
}