当我编译我的代码时,我收到 4 个警告 - 但如何让它们消失? (我不是指@SuppressWarnings)
PS:显然这一定是以前问过的 - 但要么我找不到它,要么我无法应用它。
输出
warning: [unchecked] unchecked call to BaseWorker(C) as a member of the raw type BaseWorker
[warn] return new BaseWorker(this);
warning: [unchecked] unchecked conversion
[warn] found : com.crashnote.BaseWorker
[warn] required: com.crashnote.BaseWorker<C>
[warn] return new BaseWorker(this);
warning: [unchecked] unchecked call to SubWorker(C) as a member of the raw type SubWorker
[warn] return new SubWorker(this);
warning: [unchecked] unchecked conversion
[warn] found : com.crashnote.SubWorker
[warn] required: com.crashnote.SubWorker<C>
[warn] return new SubWorker(this);
源代码
BaseConfig : 实例化BaseWorker
public class BaseConfig<C extends BaseConfig> {
public BaseConfig(final Object c) {
}
public BaseWorker<C> getWorker() {
return new BaseWorker(this);
}
}
BaseWorker
public class BaseWorker<C extends BaseConfig> {
public BaseWorker(final C config) {
}
}
SubConfig : 实例化SubWorker
class SubConfig<C extends SubConfig> extends BaseConfig<C> {
public SubConfig(final Object c) {
super(c);
}
@Override
public SubWorker<C> getWorker() {
return new SubWorker(this);
}
}
SubWorker:继承自 SubWorker
public class SubWorker<C extends BaseConfig> extends BaseWorker<C> {
public SubWorker(final C config) {
super(config);
}
}
编辑
我尝试了提供的解决方案,但由于某种原因它现在失败了。
一种)
return new BaseWorker<BaseConfig>(this);
结果是
incompatible types
[error] found : BaseWorker<BaseConfig>
[error] required: BaseWorker<C>
[error] return new BaseWorker<BaseConfig>(this);
二)
return new BaseWorker<C>(this);
结果是
cannot find symbol
[error] symbol : constructor BaseWorker(BaseConfig<C>)
[error] location: class BaseWorker<C>
[error] return new BaseWorker<C>(this);
嗯,也许我做错了什么。顺便说一句,这是 Java 6,以防万一。