我对这两个功能之间的区别有疑问:

def getFunction(checkpointPath: String,
                  sparkConf: SparkConf,
                  creatingFunc: () => StreamingContext): StreamingContext = {
    function body
  }


def getFunction(checkpointPath: String,
                  sparkConf: SparkConf,
                  creatingFunc:  => StreamingContext): StreamingContext = {
    function body
  }

因此,按名称调用的参数是相同的:
creatingFunc:  => StreamingContext


creatingFunc: () => StreamingContext

或者没有 ?

最佳答案

两者不一样。第一种情况指定按名称调用的方法参数

creatingFunc:  => StreamingContext

而第二种情况指定按值传递方法参数,其中该参数恰好是() => StreamingContex类型的函数
creatingFunc: () => StreamingContext

例如,考虑以下两种方法
def foo(arg: () => String) = ""
def foo(arg: => String) = ""

然后
foo(() => "") // resolves to call first foo
foo("")       // resolves to call second foo

10-06 03:23