为什么在Scala中使用带有`to`的变量是不可能的?

时间:2018-04-22 12:56:55

标签: scala collections range

以下内容无法编译:

opacity: condition == true ? (){ stringName = 'Steve'; return 0; }() : 0;

报告的错误是:“无法将符号解析为”

如果我将var id_last_pivot : Integer = 0 (id_last_pivot to content.length).maxBy(... 替换为数字值,则可以正常工作。

为什么?如何解决这个问题?

2 个答案:

答案 0 :(得分:9)

Integer来自java,它包含对象中基本类型的值,并且其中没有任何方法to

您需要使用包Int中的scala.Int来使用方法to

var id_last_pivot : Int = 0

现在您可以将该方法用作(id_last_pivot to content.length)

  

来自[[scala.Int]] =>的隐式转换   [[scala.runtime.RichInt]]提供有用的非原语   操作

希望这有帮助!

答案 1 :(得分:1)

如果变量-r win10-x64的类型java.lang.Integer不在您的控制之下,您还可以使用类型归属

id_last_pivot

而不是引入单独的变量。

相关问题