Scala - 函数,其类型组成为2个特征

时间:2017-09-17 14:53:12

标签: scala syntax traits

我希望我的函数接收一个实现2个特征的类型。

是否可以创建一个" adhoc"这样的特质类型?

例如:

trait t1 {
... //stuff....
}

trait t2 {
... // more stuff....
}

class MyClass {
   def functionMix(input : t1&&t2 type) {
       .... the input implements t1 and t2 trait
   }
}

1 个答案:

答案 0 :(得分:4)

不确定

trait Foo
trait Bar

def doStuff(f: Foo with Bar) = ???