【发布时间】:2022-01-05 01:16:56
【问题描述】:
问题很简单,看看下面的代码:
public class ChoiceBox<T> {}
public Class<ChoiceBox> getApplicableClass() {
return ChoiceBox.class;
}
在 Eclipse 和其他 IDE 中,会生成警告:
ChoiceBox is a raw type. References to generic type ChoiceBox<T> should be parameterized
所以我确实将 getApplicableClass 函数的返回类型更改为:
public Class<ChoiceBox<?>> getApplicableClass()
但现在的问题是,我怎样才能在没有警告的情况下返回 Class
public Class<ChoiceBox<?>> getApplicableClass() {
return ??????????????;
}
【问题讨论】:
-
可以在方法中添加
@SuppressWarnings("rawtypes")注解。 -
你好@MirekPluta,你是对的,但我们的目标是在可能的情况下找到一种“没有警告”的方法
-
我认为这是不可能的。也许你的答案在stackoverflow.com/a/2390682/9901515