我遇到了一个大问题,我不知道问题出在我的IDE的错误中,Vaadin还是我做错了什么。当我尝试使用Eclipse时,Eclipse没有找到一些方法(但是在添加点后列出对象的方法时它们就存在了)
我可以举个例子,但还有更多(如果需要,我可以提供更多):
我想将转换器设置为ComboBox。它有两种方法:
public void setConverter(java.lang.Class<?> datamodelType)
public void setConverter(Converter<T,?> converter)
我想使用第二个,所以我这样做:
myCombobox.setConverter(new Converter<User, Integer>(){
// Some interface methods
});
然后Eclipse将方法名称设置为红色,当我悬停时,我得到了这个:
The method setConverter(Class<?>) in the type AbstractField<Object> is not applicable for the arguments (new Converter<User,Integer>(){})
就好像它不知道另一种方法存在。 当我去检查课程时,当然存在方法,因为Eclipse首先列出。
我真的不知道为什么会这样,我感谢任何线索或想法。
非常感谢
答案 0 :(得分:1)
ComboBox
扩展AbstractField<Object>
,因此T
ComboBox
为Object
。
由于泛型类型参数不能被子类替换(除非指定),您必须给该方法Converter<Object, ?>
或者它与方法签名不匹配。
myCombobox.setConverter(new Converter<Object, Integer>() {
// ... cast to `User` if you like
});