Scala case class 当你有 not-used-in-equals 属性时实例化

Scala case class instantiate when you have not-used-in-equals properties

有学术成就class:

case class A3(name: String)(val s: String) {}

正在尝试实例化它。我试过了

  1. val v = A3("la")
  2. val v = A3("la", "ba")

都没用。看了一本书,http://techbus.safaribooksonline.com/book/programming/scala/9780981531687/case-classes-and-pattern-matching/case_classes_and_pattern_matching_html

我用谷歌搜索但找不到答案。

Scala IDE 消息没有帮助(更正:他们有帮助,但工具提示框不够大且背景为黑色,错过了重要部分,请参阅下面的 REPL 输出)。 REPL 帮助,需要使用两组括号,如:

val v = A3("ga")("mu")

完整回复:

scala> case class A3(name: String)(var s : String) {} defined class A3

scala> val v3 = A3("a2") :13: error: missing argument list for method apply in object A3 Unapplied methods are only converted to functions when a function type is expected. You can make this conversion explicit by writing apply _ or apply(_)(_) instead of apply. val v3 = A3("a2") ^

scala> val v3 = A3("a2")("s") v3: A3 = A3(a2)