gpt4 book ai didi

java通配符类型安全警告

转载 作者:搜寻专家 更新时间:2023-10-31 19:27:31 25 4
gpt4 key购买 nike

好吧,我有一个界面是;

public interface abc {
public<T extends JPanel> T initalize();
}

我正在实现它。这是事情,当我定义函数时:

public class Startup_thePanel extends JPanel implements abc {
public Startup_thePanel initalize() {

return this;
}
}

我在函数 initalize 上收到警告,它是“类型安全:类型的表达式 ... 需要未经检查的转换以符合 ...”。

我可以使用 suppresswarning 摆脱它,但我不想使用它。我错过了什么?

提前致谢...

最佳答案

public interface abc<T extends JPanel> {
public T initalize();
}

public class Startup_thePanel extends JPanel implements abc<Startup_thePanel> {
public Startup_thePanel initalize() {

return this;
}
}

这将使编译器知道您正在实现哪种类型的接口(interface)。

关于java通配符类型安全警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30596921/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com