【发布时间】:2014-11-27 20:16:40
【问题描述】:
只是为了好奇有没有简写
test = "test"
test
我尝试过类似的方法
(test = "test")
或
//if ((test = "test") != null) test
if (test = "test") test
//编辑:我必须在返回之前设置测试变量。
【问题讨论】:
-
你为什么要创建
var?你能举出更大的例子来说明你想要完成的事情吗? -
此代码的简写为
"test",前提是您避免使用显式返回语句。 -
你通常不需要在 scala 中使用
return,而且习惯上你应该避免使用它。只需将"test"作为函数的最后一条语句即可。 -
我必须在返回之前设置变量