【问题标题】:Scala - function which takes a type composition of 2 traitsScala - 采用 2 个特征的类型组合的函数
【发布时间】:2017-09-17 14:53:12
【问题描述】:

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

是否可以创建这样的“临时”特征类型?

例如:

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

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

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

【问题讨论】:

    标签: scala syntax traits


    【解决方案1】:

    当然:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-25
      • 2016-11-28
      • 1970-01-01
      相关资源
      最近更新 更多