1

reference to addValueChangeListener is ambiguous [ERROR] both method addValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener<V>) in com.vaadin.data.HasValue and method addValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener<T>) in com.vaadin.ui.AbstractField match

This is the compilation error i am getting during the build of project and the code is as following:

private void setTodos(List<Todo> todos) {
    removeAllComponents();
    this.todos = todos;
    todos.forEach(todo ->{
        addComponent(new TodoLayout(todo, this));
    });
}

TodoLayout.java has the valueChangeListener which is registering each field to handle the change ...

private CheckBox done;
private TextField text;

public TodoLayout(Todo todo, TodoChangeListener changeListener) {
    setSpacing(true);
    setDefaultComponentAlignment(Alignment.MIDDLE_CENTER);
    done = new CheckBox();
    text = new TextField();
    text.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS);
    text.setWidth("100%");

    Binder<Todo> binder = new Binder<>();
    binder.forField(text).bind(Todo::getText, Todo::setText);
    binder.bind(done, Todo::isDone, Todo::setDone);
    binder.setBean(todo);
    addComponents(done, text);

    Arrays.asList(done, text).forEach(field ->
            field.addValueChangeListener(change ->    //line where getting the error
            changeListener.todoChanged(todo))
        );

}

As according to the logic each field is registered with only one change listener, then how it is ambiguous.

Thankyou.

  • [The ambiguity](https://stackoverflow.com/questions/32294140/java-8-reference-to-method-is-ambiguous) is related to the method that should be called to add the listener. **1)** Anyway, your code compiles just fine on my PC with Java 1.8_162 & Vaadin 8.3.1 after creating some stubs for `Todo` & `TodoChangeListener`, so we'll probably need a [sscce](http://sscce.org) to figure it out. Probably `TodoLayout`, `Todo` & `TodoChangeListener` with java & vaadin versions will suffice. – Morfic Mar 23 '18 at 13:08
  • **2)** You can probably just use `binder.addValueChangeListener(event -> changeListener.todoChanged(todo));` instead of adding the listeners to each field yourself. – Morfic Mar 23 '18 at 13:12

0 Answers0