gpt4 book ai didi

Java Vaadin 组合框警告 Intellij : unclear if a varargs or non-varargs call is desired

转载 作者:行者123 更新时间:2023-12-02 08:57:15 27 4
gpt4 key购买 nike

我的代码正在运行,但我收到了来自 Intelij 的警告(代码突出显示):不清楚是否需要可变参数或非可变参数调用。但代码确实完善了我想要的或我期望的,用值填充组合。当我单击组合中的项目时,它会返回正确的枚举所以任何人都可以帮助我解决这个警告。

  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中有两个重载方法类 addItems :

  1. public void addItems(Collection<?> itemIds) throws UnsupportedOperationException
  2. 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.

关于Java Vaadin 组合框警告 Intellij : unclear if a varargs or non-varargs call is desired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60418501/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com