scala_def定义函数

scala def 定义函数的区别

1
def foo = {1}

A function which should return a non-Unit value must be declared with the = notation (although of course the compiler can infer the return-type from the expression’s type).

1
def foo {1}

返回类型为Unit
In Scala if a method declaration does not have an equal sign before its body, the compiler infers that the result type will be Unit

参考
scala: ‘def foo = {1}’ vs ‘def foo {1}’

欢迎关注我的公众号:沉迷Spring
显示 Gitment 评论
0%