相关疑难解决方法(0)

依赖类型不适用于构造函数?

路径相关类型很有用:

trait Sys {
  type Global
}
def foo[S <: Sys](system: S)(global: system.Global) = ()
Run Code Online (Sandbox Code Playgroud)

为什么这对构造函数不起作用?

class Foo[S <: Sys](val system: S)(val global: system.Global)
Run Code Online (Sandbox Code Playgroud)

或者我只是做错了?

constructor scala path-dependent-type

12
推荐指数
1
解决办法
723
查看次数

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 ×2

constructor ×1

path-dependent-type ×1