我想了解为什么编译器会抱怨这个接口声明。T 是泛型类型参数。
static class Bar<T extends Comparable<?>> {}
static interface Foo<T extends Comparable<?>, Bar<T>> { }
编译器说
Error:(64, 53) Groovyc: unexpected token: <
(64, 53) 是<
第二个之前T
。
我想要的是有一个接口 Foo,它可以与包含扩展 Comparable 的任何类的 Bar 实例一起使用。
我想要的是有一个接口 Foo,它可以与包含扩展 Comparable 的任何类的 Bar 实例一起使用。
那么 Bar 应该是通用的,接口应该只是在 T 上参数化:
class Bar<T> {...}
interface Foo<T extends Comparable<?>> {
Bar<T> doSomething(Bar<T> otherBar);
...
}
或者,如果您还希望 Foo 在扩展 Bar 的类型上是通用的,那么它应该类似于
interface Foo<T extends Comparable<?>, B extends Bar<T>> {
B doSomething(B otherBar);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句