我是scala的新手,如果问题很愚蠢,我会事先道歉。我正在浏览这个scala代码,我很困惑以下代码如何工作
abstract class ClusterSimulatorDesc(val runTime: Double) {
def newSimulator(constantThinkTim: Double,
perTaskThinkTime: Double,
blackListPercent: Double,
schedulerWorkloadsToSweepOver: Map[String, Seq[String]],
workloadToSchedulerMap: Map[String, Seq[String]],
cellStateDesc: CellStateDesc,
workloads: Seq[Workload],
prefillWorkloads: Seq[Workload],
logging: Boolean = false): ClusterSimulator
}
class ClusterSimulator(val cellState: CellState,
val schedulers: Map[String, Scheduler],
val workloadToSchedulerMap: Map[String, Seq[String]],
val workloads: Seq[Workload],
prefillWorkloads: Seq[Workload],
logging: Boolean = false,
monitorUtilization: Boolean = true,
monitoringPeriod: Double = 1.0)
extends Simulator(logging) {
现在,如果我有一个函数调用,如: -
simulatorDesc: ClusterSimulatorDesc
val simulator =
simulatorDesc.newSimulator(constantThinkTime,
perTaskThinkTime,
blackListPercent,
schedulerWorkloadsToSweepOver,
schedulerWorkloadMap,
workloadDesc.cellStateDesc,
workloads,
prefillWorkloads,
logging)
现在我的问题是," ClusterSimulator"在抽象类声明结束时呢? 并且,如何调用" newSimulator"函数发生了,考虑到它在抽象类中声明了吗?
答案 0 :(得分:2)
75%
方法def newSimulator(....): ClusterSimulator
在调用时会返回newSimulator()
的实例。
ClusterSimulator
simulatorDesc: ClusterSimulatorDesc
无法实例化,因为它是抽象的,但可以实例化扩展ClusterSimulatorDesc
的类, 类的实例也 ClusterSimulatorDesc
的一个实例,可以调用它的方法。