score:5
gplayer(1, 42, 1, 9)
is the same as writing
gplayer.apply(1, 42, 1, 9)
so instead of defining an alternative constructor, you should define an alternative apply
method in the companion object gplayer
.
case class gplayer(id: long, glimpleid: long, layerorder: int, created: long, attachments: list[gpattachment])
object gplayer {
def apply(id: long, glimpleid: long, layerorder: int, created: long) = gplayer(id, glimpleid, layerorder, created, list[gpattachment]())
}
if you want to call the altnernative constructor instead, you must add the new
-keyword:
new gplayer(1, 42, 1, 9)
edit: as nicolas cailloux mentioned, your alternative constructor is really just providing a default value for the member attachments
, so the best solution would actually be to not introduce a new method, but to specify this default value as follows:
case class gplayer(id: long, glimpleid: long, layerorder: int, created: long, attachments: list[gpattachment] = nil)
score:2
note that in your case, you could just provide a default value for the last argument :
case class gplayer(id: long, glimpleid: long, layerorder: int, created: long, attachments: list[gpattachment] = list())
Source: stackoverflow.com
Related Query
- Alternate constructor on Scala case class not defined: not enough arguments for method
- Removing a class constructor results in "not enough arguments for constructor" (recompilation not working?)
- pass variable number of arguments in scala (2.8) case class to parent constructor
- How would I get a list of constructor arguments for a case class in Scala?
- Scala is not creating private constructor for companion class
- Not enough arguments for constructor although I use the Option[] Type
- error: not enough arguments for method withColumn: Scala spark
- Scala - Not enough arguments for method count
- Scala: not enough arguments for constructor DictionaryLemmatizer
- Is JSON formatting not enough for parsing case class having > 22 fields?
- Not enough arguments for a constructor
- Using Scala Breeze numerics results in error: not enough arguments for method apply
- Possible ways for currying case class constructor in scala
- Scala case class private constructor but public apply method
- Why does Scala not have a return/unit function defined for each monad (in contrast to Haskell)?
- Why not make every Scala class a case class?
- Scala spark: how to use dataset for a case class with the schema has snake_case?
- scala Duration: "This class is not meant as a general purpose representation of time, it is optimized for the needs of scala.concurrent."
- Scala case class private constructor isn't private
- How do I add a no-arg constructor to a Scala case class with a macro annotation?
- Scala Dynamic Parse Json using case class No Manifest available for T
- scala case class equals (==) not working as expected
- How can I create an instance of a Case Class with constructor arguments with no Parameters in Scala?
- Partial EMMA code coverage in Scala Case Class for IntelliJ IDEA 10.5
- Scala error: type arguments do not conform to class type parameter bounds
- scala generic encoder for spark case class
- Scala case class copy constructor with dynamic fields
- Seemingly spurious "does not take arguments" error with case class constructor
- Scala case class arguments instantiation from array
- java.lang.NoSuchMethodException for init method in Scala case class
More Query from same tag
- What is the purpose of the Adapted Response?
- How to capture the output of a process in Scala
- How to subtract days in scala?
- PlaySpecification not found in Play 2.6.3
- Context bound for nested type
- scala create val for outer scope
- Akka Slick and ThreadLocal
- Sum of sequence of Vectors in Scala
- Play 2 postgres driver not found
- How to import hbase-testing-util in SBT?
- Exchanging type parameters with abstract types
- Shapeless code to convert Map[String, Any] to case class cannot handle optional substructures
- Is the map generator from the EPFL online course able to generate every possible map?
- Questions about scala
- Filter CSV in scala?
- scala: How to pass an expanded list as varargs into a method?
- sbt-assembly does not pick up configuration specific settings
- scala unmarshelling xml want to capture cdata fields
- Finagle server dont ready after start
- Scala: Calculate levenshtein distance between 2 strings
- How to Read textFile based on another textFile 1st column as a KEY
- Not Getting expected output for reduceGroup function in scala
- Filter an RDD based on number of occurrences
- sbt shading two versions of a dependency
- Can a Scala function be written such that it gets any function and returns it with its arguments reversed?
- How to debug custom slug crashing
- Scala types: reflect: How to find least upper bound of two types at runtime
- Issue with HashMap ordering on generic type in Scala
- Concatenating Saddle Series into one Frame
- Why is it possible to mix in classes in a type field?