我正在使用庫函數,它爲參數minPartition使用默認參數值。我有一個包裝函數,我稱之爲庫函數。我希望包裝函數能夠工作的方式是 - 如果爲minPartition傳遞一個值,則在調用該函數時將使用此值。否則,我將使用默認值並且不傳遞參數。我如何在Scala中做到這一點?Scala - 使用默認參數值打包函數
def read(foo: String, minPartitions: Integer = ????): RDD[String] = {
val rdd = sc.hadoopRDD(jobConf,
classOf[InputFormat],
classOf[BytesWritable],
classOf[BytesWritable],
minPartitions // optional - default value will be used
)
}
也許用'def read(foo:String,partitions:Int)= read(foo,Some(分區))'和'def read(foo:String)= read(foo,None)爲了方便起見,讓它更像是調用者的「默認參數」。 – PH88