[英]Scala Nested expression does not take parameters
Team, 球队,
New to scala and learning step by step. Scala的新手和逐步学习。 while learning nested scopes in expression blocks, wrote below lines of code
在学习表达式块中的嵌套作用域时,写在下面的代码行中
object ExpressionTest extends App {
val area = {
val PI = 3.14
PI * 10
{
val PI= 100
PI * 2
}
}
println(area)
}
Getting below exception at runtime . 在运行时低于异常。
Error:(9, 5) Int(10) does not take parameters
I am using Intellji
In Scala it is possible to specify a function parameter as a block. 在Scala中,可以将功能参数指定为块。 The compiler thinks that your inner block is a parameter to
10
from the previous line. 编译器认为您的内部块是上一行的
10
的参数。
To help the compiler understand what you mean, you can add a ;
为了帮助编译器理解您的意思,您可以添加
;
at the end of the line: 在该行的末尾:
val area = {
val PI = 3.14
PI * 10;
{
val PI = 100
PI * 2
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.