object Test13 { def sum(x:Int=200,y:Int=100): Int={ x+y } //给参数一个默认值,如果调用时,没有传入参数。就直接使用默认参数值 def say:Unit={ println("你好~~") } def main(args: Array[String]): Unit = { say say say println("--------------------") val rs1=sum(1) println(rs1) val rs2 = sum(2) println(rs2) val rs3=sum(1,1) println(rs3) var rs4=sum(y=2) println(rs4) }
scala函数参数的默认值
最新推荐文章于 2024-11-11 16:20:10 发布