Generics 构造函数不能应用于';(T) &x27;使用@CompileStatic和泛型类时出错
我正在尝试“修复”一些我一直在升级的其他代码 我将其归结为一个简单的泛型类示例,然后讨论该类的使用 首先,我声明了一个泛型参数化类,如下所示Generics 构造函数不能应用于';(T) &x27;使用@CompileStatic和泛型类时出错,generics,groovy,compile-static,Generics,Groovy,Compile Static,我正在尝试“修复”一些我一直在升级的其他代码 我将其归结为一个简单的泛型类示例,然后讨论该类的使用 首先,我声明了一个泛型参数化类,如下所示 //generic class class WillsAgent<T> { public WillsAgent(T data) {//do nothing with this } } @CompileStatic public abstract class Test<T> { public WillsA
//generic class
class WillsAgent<T> {
public WillsAgent(T data) {//do nothing with this }
}
@CompileStatic
public abstract class Test<T> {
public WillsAgent<T> agent( T state) {
final WillsAgent<T> safe = new WillsAgent<T> (state)
return safe
}
}
//泛型类
阶级意志{
public WillsAgent(T data){//对此不做任何操作}
}
然后一个消费类尝试这样使用它
//generic class
class WillsAgent<T> {
public WillsAgent(T data) {//do nothing with this }
}
@CompileStatic
public abstract class Test<T> {
public WillsAgent<T> agent( T state) {
final WillsAgent<T> safe = new WillsAgent<T> (state)
return safe
}
}
@CompileStatic
公共抽象类测试{
公共遗嘱代理人(T州){
最终遗嘱安全=新遗嘱(状态)
保险箱
}
}
当@CompileStatic声明起作用时,IDE在(状态)下显示一个红色的波形,将参数传递给构造函数,如下所示
如果我注释掉@CompileStatic声明,错误就会消失
如果我将鼠标悬停在曲线上(启用@CompileStatic),它会显示:groovyx.gpars.agent.WillsAgent中的构造函数“WillsAgent”不能应用于“(T)
除了删除@CompileStatic之外,我不知道如何更正此问题
有人知道它为什么会抱怨这个问题,以及如何解决它吗?快速修复:替换以下行:
final WillsAgent<T> safe = new WillsAgent<T>(state)