Getting "incorrect number of arguments" when omitting parameter with default values in scala

StackOverflow https://stackoverflow.com/questions/20940942

  •  24-09-2022
  •  | 
  •  

Question

For a call to the following constructor:

class SparkContext(
    val master: String,
    val appName: String,
    val sparkHome: String = null,
    val jars: Seq[String] = Nil,
    val environment: Map[String, String] = Map())
  extends Logging {

In the following notice the last parameter is commented out:

val spark = new SparkContext("localhost", "GroupBy Test",
  System.getenv("SPARK_HOME"), Seq(System.getenv("SPARK_EXAMPLES_JAR")) /* , Map() */)

Then the scala compiler (2.9.2) complains:

not enough arguments for constructor SparkContext: (master: String, appName: String, sparkHome: String, jars: Seq[String], environment: scala.collection.Map[String,String])spark.SparkContext
    val spark = new SparkContext("localhost", "GroupBy Test",
                ^

When it is uncommented, then the code compiles. So .. what is wrong here AFA omitting the last parameter (and scala using the default value) ?

Note I am on 2.9.3

Was it helpful?

Solution

I have seen this error when trying to use one major version (first + second number) of the Scala compiler and a different version of a library, e.g. 2.9 compiler vs. 2.10-compiled library. Unfortunately, Scala-compiled libraries are not binary compatible between 2.8, 2.9, or 2.10, nor between different minor versions of 2.8 (different third number). In other words, all of your Scala libraries, as well as your code itself, have to be compiled with the same major version, and in the case of 2.8.x, with the same minor version as well. Binary compatibility does exist between minor versions starting with 2.10, and in most cases with 2.9, although there are some edge cases in the 2.9 series.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top