我是否需要尾随分号来消除此代码的歧义? [英] Do I need a trailing semicolon to disambiguate this code?
本文介绍了我是否需要尾随分号来消除此代码的歧义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我省略分号,此代码将无法编译.
If I omit the semicolon, this code doesn't compile.
def checkRadioButton(xml: DslBuilder): String => XmlTree = {
val inputs = top(xml).\\*(hasLocalNameX("input"));
{ (buttonValue: String) =>
// code omitted
}
}
我的猜测是,如果没有分号,scalac 认为偏函数是 \\*
方法的另一个参数,而不是返回值.(它实际上不是一个偏函数,顺便说一下,它是一个全函数.)
My guess is that, without the semicolon, scalac thinks that the partial function is another argument to the \\*
method, instead of the return value. (It isn't actually a partial function, by the way, it's a total function.)
这里可以不用分号吗?我以前从未在 Scala 中在行尾使用分号.
Can I do without the semicolon here? I've never had to use a semicolon at the end of a line before in Scala.
推荐答案
我会这样写:
def checkRadioButton(xml: DslBuilder): String => XmlTree = {
val inputs = top(xml).\\*(hasLocalNameX("input"));
(buttonValue: String) => { // <-- changed position of {
// code omitted
}
}
这篇关于我是否需要尾随分号来消除此代码的歧义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文