Groovy泛型失败 [英] Groovy Generics failure
本文介绍了Groovy泛型失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<
): interface A {
< T> T getByClass(Class< T> clazz)
}
如何编写groovy
解决方案
Groovy解析器不处理以通用信息开头的方法签名 ...
它会分析你是否添加了public修饰符:
interface A {
public< T> T getByClass(Class< T> clazz)
}
虽然我不相信你在编译时会获得任何类型检查以添加此批注
Besides groovy is way more dynamic then java...
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?
解决方案
The Groovy parser does not handle method signatures beginning with Generic information...
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屋!
查看全文