Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Scala 似乎不喜欢我为 String val 赋值。每当我尝试时都会出错:
val s = new String s = "hi"
Aval是最终的,您不能重新分配它。
val
val s = "hi"
这行得通(但你为什么要这样做?)
var s = new String s = "hi"
(编辑)改为这样做
var s = "hi"
Scala 推断类型;在这种情况下,您不需要指定 String
是你所需要的全部。如果您想明确说明类型,请选择
val s: String = "hi"