score:10
Accepted answer
Because you could do this:
case class Example(value: String = "default", otherValues: String*)
And now if you call Example("Hello", "world")
, does the first "Hello"
belongs to value
or to otherValues
?
You could argue that the types in your examples are different, but the rules become too complicated to follow. For example repeated parameters often used with Any
type. This example case class Example(value: Option[String] = None, otherValues: Any*)
has different types, but still struggles with the same problem
Source: stackoverflow.com
Related Query
- Why are default arguments not allowed in a Scala section with repeated parameters?
- Scala named and default arguments in conjunction with implicit parameters
- Why does Scala not infer the type parameters when pattern matching with @
- Why the following Scala code does not compile unless explicit type parameters are added?
- Why are scala Vals not lazy by default
- Treat scala function with default parameter type as if it did not have default parameters
- Why is it the empty element of a List are not replaced with default value in Scala?
- Scala generics: why two types with the same upper bound are not compatible?
- JsonIgnore for Scala method with default parameters does not work as expected
- Why does the Scala compiler disallow overloaded methods with default arguments?
- Why does pattern matching in Scala not work with variables?
- Are Options and named default arguments like oil and water in a Scala API?
- Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?
- Why are variables not allowed in alternative patterns?
- Why does Scala compiler fail with "no ': _*' annotation allowed here" when Row does accept varargs?
- Why doesn't Scala fully infer type parameters when type parameters are nested?
- Why aren't type parameters allowed in Scala auxiliary constructors?
- Why can a method returning Unit be overridden with method returning String when return types are not explicitly given?
- Why are concrete function implementations in traits compiled to bridge methods in Scala 2.9.x but not in 2.8.x?
- Why Final variables in scala are allowed to change values
- Why does overloading polymorphic methods with different upper bounds not compile in Scala
- Why scala does not unify this type lambda with underlying type?
- Why are parenthesis required for invoking methods with default arguments?
- scala 2.9: plans for type inference of function parameters with default arguments?
- why yield can not work with while loop in scala
- Why are Scala class methods not first-class citizens?
- In Scala, how does one write a class with a constructor, not all of whose arguments are class members?
- Why is instantiating a trait with default values in Scala a compilation error?
- Scala working with Java libraries not specifying collections' type parameters
- Why are implicit variables not initialized in Scala when called from unit test?
More Query from same tag
- Apache Flink got exception: java.lang.IllegalStateException: Trying to work with offloaded serialized shuffle descriptors
- How do I chain calls that take blocks as inputs?
- Create multiple target for multiproject in sbt
- Why is implicit resolution failing?
- Scala Actor Based Web Server
- Scala: for-comprehension with recursive Future
- Odd typing bug in Scala
- SBT - Is there a way to ignore duplicate mappings in copyResources?
- Slick 3.0 convert Rep(Bind) to value
- Merge List[List[_]] conditionally
- Pre append regex pattern to split and map case class to splitted
- Scala Spark Handle Single Quote Characters With Commas
- Scala- How to get a Vector's contained class?
- Extract kmeans cluster information using Apache Spark
- Compile scala project with gradle: MissingRequirementError
- Is it possible to use reflection to find the actual type of a field declared to be a Scala Enumeration subtype?
- managing akka one-off actors
- Find an element in a List by comparing with another list in scala
- Abstract parametric types in Scala
- Scala for comprehension returns type mismatch; found : Unit
- If you have Traits, do you stop using interfaces, Abstract base classes, and multiple inheritance?
- Project compiles fine in IntelliJ, Tomcat says java.lang.NoClassDefFoundError: my/package/name/blah
- Scala Predicates
- Why Scala's transient is not a keyword but an annotation?
- Scalaz: how do I use `traverseS` on regular scala List?
- Exception on download: sun.security.validator.ValidatorException: No trusted certificate found
- IllegalAccessError when running spark job in EMR
- scala rdd flatmap to generate multiple row from one row to en-fill gap of rows issue
- Can I mimic Scala SIP-18-syle imports?
- Inferring parameter type for a lambda (again!)