【问题标题】:Groovy static compilation fails when using generics and extended traits使用泛型和扩展特征时,Groovy 静态编译失败
【发布时间】:2017-03-10 22:33:06
【问题描述】:

编译以下代码时出现错误:

import groovy.transform.CompileStatic

@CompileStatic
class Test {
  trait BaseTrait {}
  trait ExtendingTrait extends BaseTrait {}
  static class BaseTraitImplementor implements BaseTrait {}
  static class ExtendingTraitImplementor implements ExtendingTrait {}
  static class BothTraitImplementor implements ExtendingTrait, BaseTrait {}
  static class UsingTraits<T extends BaseTrait> {}
  UsingTraits<BaseTraitImplementor> instance1
  UsingTraits<ExtendingTraitImplementor> instance2 // <- compiler complains here
  UsingTraits<BothTraitImplementor> instance3
}

编译错误:

Groovy-Eclipse: Bound mismatch: The type Test.ExtendingTraitImplementor is not a valid substitute for the bounded parameter <T extends Test.BaseTrait> of the type Test.UsingTraits<T>

看起来编译器无法解析 ExtendingTrait 实际上扩展了 BaseTrait,我需要手动提供它(请参阅 BothTraitImplementor 类)。

我做错了什么还是一个错误?

【问题讨论】:

    标签: java generics groovy compiler-errors traits


    【解决方案1】:

    我找到了答案。事实证明,Groovy-Eclipse 编译器已经过时并且有很多错误。当我切换到 groovyc 时,一切都很顺利。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 2016-08-11
      • 2012-11-26
      相关资源
      最近更新 更多