小编Gel*_*ion的帖子

Scala 中每个参数的单独构造函数

我试图从 Apache Spark 的源代码中理解以下类声明:

case class HadoopFsRelation(location: FileIndex, ...)(val sparkSession: SparkSession)
Run Code Online (Sandbox Code Playgroud)

我想知道为什么它具有采用 SparkSession 的第二个构造函数。

我只是写了一些例子来澄清一些观点:

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 …
Run Code Online (Sandbox Code Playgroud)

scala

0
推荐指数
1
解决办法
99
查看次数

标签 统计

scala ×1