我遇到了一个大问题,我不知道问题是否出在我的 IDE、Vaadin 上,或者我做错了什么。当我尝试使用某些方法时,Eclipse 没有找到它们(但在添加点后列出对象的方法时它们就在那里)
我可以给你一个例子,但还有更多(如果需要的话我可以提供更多):
我想将转换器设置为组合框。有两种方法:
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 首先列出的那样。
我真的不知道为什么会发生这种情况,我很感激任何线索或想法。
非常感谢
最佳答案
ComboBox
延伸AbstractField<Object>
所以T
对于 ComboBox
是 Object
.
由于泛型类型参数不能被子类替换(除非指定),您必须为该方法提供 Converter<Object, ?>
或者它与方法签名不匹配。
myCombobox.setConverter(new Converter<Object, Integer>() {
// ... cast to `User` if you like
});
关于java - Eclipse 未找到某些声明的方法(在 Vaadin 库中),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18834417/