Scala case class instantiate when you have not-used-in-equals properties -
have academic class:
case class a3(name: string)(val s: string) {}
trying instantiate it. tried
val v = a3("la")
val v = a3("la", "ba")
neither worked. looked @ book, http://techbus.safaribooksonline.com/book/programming/scala/9780981531687/case-classes-and-pattern-matching/case_classes_and_pattern_matching_html
i googled not answer.
scala ide messages did not (correction : do, tool tip box not big enough , had black background, missed important part, see below repl output). repl helped, need use 2 sets of parenthesis like:
val v = a3("ga")("mu")
full repl:
scala> case class a3(name: string)(var s : string) {} defined class a3
scala> val v3 = a3("a2") :13: error: missing argument list method apply in object a3 unapplied methods converted functions when function type expected. can make conversion explicit writing
apply _
orapply(_)(_)
instead ofapply
. val v3 = a3("a2") ^scala> val v3 = a3("a2")("s") v3: a3 = a3(a2)
Comments
Post a Comment