Groovy 泛型失败 [英] Groovy Generics failure
本文介绍了Groovy 泛型失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
除了 groovy 比 java 更动态...
Besides groovy is way more dynamic then java...
为什么这是 groovy 中的编译时错误(意外标记 <
):
Why is this a compile time error in groovy (unexpected token <
):
interface A {
<T> T getByClass(Class<T> clazz)
}
我如何以常规方式编写此代码?
How do I write this the groovy way?
推荐答案
Groovy 解析器不处理 以通用信息开头的方法签名...
The Groovy parser does not handle method signatures beginning with Generic information...
如果添加 public 修饰符,它会解析:
It parses if you add the public modifier:
interface A {
public <T> T getByClass( Class<T> clazz )
}
虽然我不相信你会在编译时获得任何类型检查来添加这个注解
Though I don't believe you'll gain any type checking at compile time for adding this annotation
这篇关于Groovy 泛型失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文