Java Vaadin 组合框警告 Intellij:不清楚是否需要可变参数或非可变参数调用
Java Vaadin combobox warning Intellij : unclear if a varargs or non-varargs call is desired
我的代码可以正常工作,但我收到了来自 Intelij 的警告(代码被突出显示):unclear if a varargs or non-varargs call is desired
。
但是代码确实完善了我想要的或我期望的,用值填充组合。
当我点击组合中的项目时,它 returns 我正确枚举
所以任何人都可以帮我解决这个警告。
ComboBox comboStatus = new ComboBox();
comboStatus.addItems(BatchStatusCode.values());
警告在第二行
其中 BatchStatusCode 是一个相对简单的枚举
public enum BatchStatusCode {
RUNNING("R","RUNNING"),
FINISHED("F","FINISHED"),
CANCELED("C","CANCELED");
.... some code
BatchStatusCode(final String code,final String fullName) {
this.code = code;this.fullName = fullName;
}
public String getCode() {
return code;
}
public String getFullName() { return fullName;}
.... some code
免责声明:Vaadin 7 似乎是唯一具有此方法的版本,因此我假设您正在使用它。如果我错了,请纠正我
该错误表明编译器不确定您想要使用哪种方法。是变参数的还是只带参数的
在 AbstractSelect
class 中有两个重载方法用于 addItems
:
public void addItems(Collection<?> itemIds) throws UnsupportedOperationException
public void addItems(Object... itemId) throws UnsupportedOperationException
因此,解决方案可以简单地忽略警告或向编译器明确说明您要使用的方法。例如,像这样:
comboBox.addItems(Arrays.asList(BatchStatusCode.values()));
编辑:实际上这不是原因。但我会把它留在这里
Enum
的 values()
的 问题 是由编译器 when it creates an enum 生成的。
The compiler automatically adds some special methods when it creates an enum.
For example, they have a static values method that returns an array containing all
of the values of the enum in the order they are declared.
我的代码可以正常工作,但我收到了来自 Intelij 的警告(代码被突出显示):unclear if a varargs or non-varargs call is desired
。
但是代码确实完善了我想要的或我期望的,用值填充组合。
当我点击组合中的项目时,它 returns 我正确枚举
所以任何人都可以帮我解决这个警告。
ComboBox comboStatus = new ComboBox();
comboStatus.addItems(BatchStatusCode.values());
警告在第二行 其中 BatchStatusCode 是一个相对简单的枚举
public enum BatchStatusCode {
RUNNING("R","RUNNING"),
FINISHED("F","FINISHED"),
CANCELED("C","CANCELED");
.... some code
BatchStatusCode(final String code,final String fullName) {
this.code = code;this.fullName = fullName;
}
public String getCode() {
return code;
}
public String getFullName() { return fullName;}
.... some code
免责声明:Vaadin 7 似乎是唯一具有此方法的版本,因此我假设您正在使用它。如果我错了,请纠正我
该错误表明编译器不确定您想要使用哪种方法。是变参数的还是只带参数的
在 AbstractSelect
class 中有两个重载方法用于 addItems
:
public void addItems(Collection<?> itemIds) throws UnsupportedOperationException
public void addItems(Object... itemId) throws UnsupportedOperationException
因此,解决方案可以简单地忽略警告或向编译器明确说明您要使用的方法。例如,像这样:
comboBox.addItems(Arrays.asList(BatchStatusCode.values()));
编辑:实际上这不是原因。但我会把它留在这里
Enum
的 values()
的 问题 是由编译器 when it creates an enum 生成的。
The compiler automatically adds some special methods when it creates an enum.
For example, they have a static values method that returns an array containing all
of the values of the enum in the order they are declared.