I'm trying to understand the following class declaration from the source code of Apache Spark:
case class HadoopFsRelation(location: FileIndex, ...)(val sparkSession: SparkSession)
I am wondering why it has the second constructor which takes SparkSession.
I just wrote some examples to clarify some points:
class Person(firstName: String)(lastName: String)(val age: Int) {
def tellMeAboutYourSelf() = {
//basically I have access to all three arguments
s"$firstName, $lastName - $age"
}
}
object Main extends App {
//no errors are shown, though it fails during compilation:
//missing argument lis for constructor Person
val singleArg: Person = new Person("Harry")
//surprisingly no errors are shown but it also fails during compilation:
//Person does not take parameters
val twoArgsCurrying: Person = singleArg("Potter")
//no errors, and the same compilation failure
//missing argument list for constructor Person
//a pure expression does nothing in statement position; you may be omitting necessary parentheses
val harry: Person = new Person("Harry")("Potter"){100}
//finally this works
val harry: Person = new Person("Harry")("Potter")(100)
println(harry.tellMeAboutYourSelf())
}
So the question what's the point in using such construction and why it is allowed in Scala?