定义
函数和方法的区别
- 核心概念
- 为完成某一功能的程序语句的集合,称为函数。
类中的函数称之方法。
Scala 语言可以在任何的语法结构中声明任何的语法
- 函数没有重载和重写的概念;方法可以进行重载和重写
Scala 中函数可以嵌套定义 ```scala def test(): Unit = { println(“无参, 无返回值”) } test()
//报错, 不支持重载 def test(name: String): Unit = { println() }
//嵌套定义 def test(): Unit = { println(“无参, 无返回值”)
def test3(name:String): Unit = { println(“函数可以嵌套定义”) }
} test() ```