Java 无法从类型T转换为类型T?
使用静态工厂模式时出现了一个奇怪的错误。我错过了什么?代码如下:Java 无法从类型T转换为类型T?,java,Java,使用静态工厂模式时出现了一个奇怪的错误。我错过了什么?代码如下: class subclass<T> extends immutablestruct<T>{ private immutablestruct f; private T x; //constructor <T> subclass(T y, immutablestruct<T> f ){ this.x = y; //this is there the error is
class subclass<T> extends immutablestruct<T>{
private immutablestruct f;
private T x;
//constructor
<T> subclass(T y, immutablestruct<T> f ){
this.x = y; //this is there the error is
this.f = f;
}
类子类扩展了immutablestruct{
私有免疫结构f;
私人信托;
//建造师
子类(TY,immutablestruct f){
this.x=y;//这就是错误所在
这个。f=f;
}
从构造函数声明中删除
。现在您正在声明第二个泛型参数,同时可以访问旧的T
值:
//constructor
subclass(T y, immutablestruct<T> f ){
//构造函数
子类(TY,immutablestruct f){
no所有小写类名,如果您使用小写t
而不是t