Search code examples
javaintellij-ideacomboboxvaadin

Java Vaadin combobox warning Intellij : unclear if a varargs or non-varargs call is desired


My code is working, but I've got a warning from Intelij (code gets highlighted) : unclear if a varargs or non-varargs call is desired. But code does perfect what I want or what I expect, fill the combo with the values. When I click on the item in the combo, it returns me right enum So anyone can help me to fix this warning.

  ComboBox comboStatus = new ComboBox();
  comboStatus.addItems(BatchStatusCode.values());

The warning is on the second line Where BatchStatusCode is a relative simple enum

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

Solution

  • Disclaimer: Vaadin 7 seems to be the only one version having this method, so my assumption is that you are using it. Please, correct me, if I am wrong

    The error states that compiler is not sure what method exactly you would like to use. Is it the one taking the variable amount of parameters or the one taking only one.

    There are two overloaded methods in the AbstractSelect class for the addItems:

    1. public void addItems(Collection<?> itemIds) throws UnsupportedOperationException
    2. public void addItems(Object... itemId) throws UnsupportedOperationException

    So, solution could be simply ignore the warning or make it explicit to the compiler what method you would like to use. For example, like this : comboBox.addItems(Arrays.asList(BatchStatusCode.values()));


    Edit: This is not the cause, actually. But I will leave it here

    The problem with the Enum's values() is that it's generated by the compiler 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.