Scala - 采用 2 个特征的类型组合的函数
Scala - function which takes a type composition of 2 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
}
}
当然可以:
trait Foo
trait Bar
def doStuff(f: Foo with Bar) = ???
我希望我的函数接收一个实现 2 个特征的类型。
是否可以创建这样的 "adhoc" 特征类型?
例如:
trait t1 {
... //stuff....
}
trait t2 {
... // more stuff....
}
class MyClass {
def functionMix(input : t1&&t2 type) {
.... the input implements t1 and t2 trait
}
}
当然可以:
trait Foo
trait Bar
def doStuff(f: Foo with Bar) = ???