Scala方法需要具有多重继承的参数模板



我知道JAVA允许生成如下的通用方法(见此处):

public <T extends Pet & YellableAt> void yellAtPet(T arg) {
    arg.yellAt("Don't go there!"); 
    arg.pet("Good Boy");
}

我希望能够在scala中做同样的事情,例如:

 def addWorkers[T <: BuiltInfrastructure & TraitBuiltRecruter](bi : T, nbre : n){
   // do somthing
 }

感谢

def addWorkers[T <: BuiltInfrastructure with TraitBuiltRecruter](bi : T, nbre : n)

甚至(因为您不需要T):

def addWorkers(bi: BuiltInfrastructure with TraitBuiltRecruter, nbre : n)

最新更新