NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
一组关于抽象方法、字段和类型的规格说明。 <br/> **使用方式1:** ```scala object App{ def main(args: Array[String]): Unit = { // 结构类型作为函数参数 // {def sayHello():Unit} 就是结构类型 def fun(a: {def sayHello():Unit}): Unit = { a.sayHello() } // 函数调用 fun(new {def sayHello():Unit = println("hello")}) // hello } } ``` <br/> **使用方式2:** ```scala object App{ def main(args: Array[String]): Unit = { // 定义结构类型 type X = { def sayHello():Unit } // 结构类型作为函数参数 def fun(a: X): Unit = { a.sayHello() } // 函数调用 fun(new {def sayHello():Unit = println("hello")}) // hello } } ```