【发布时间】:2020-12-31 15:17:30
【问题描述】:
好的,所以我一直在努力解决这个问题,希望得到一些建议。
我有一个类 Bar 需要连接一个类型化参数。
@Component
@RequiredArgsConstructor
@Scope(value = "prototype")
public class Bar<T> extends Foo<T> {
private final Utility utility;
public Bar<T> init(String a, int b) {
//initializations
}
//some more methods
}
在我看来,我可以像这样使用ApplicationContext 连接课程,
Foo<Detail> foo = applicationContext.getBean(Bar.class).init(a,b);
但这会引发警告,
Type safety: The expression of type Bar needs unchecked conversion to conform to Foo<Detail>.
现在我明白这个问题是因为我在使用 ApplicationContext 初始化 Bar 类的 bean 时没有提及 typed 参数。
Question is, what might be the right syntax to mention the typed parameter <Detail> in the above statement?
【问题讨论】:
标签: java spring-boot generics type-safety