reference to addListener is ambiguous

Hi,

I get the following compilation error: “reference to addListener is ambiguous, both method addListener(com.vaadin.ui.Button.ClickListener) in com.vaadin.ui.Button and method addListener(com.vaadin.event.FieldEvents.BlurListener) in com.vaadin.ui.Button match”.

In fact, the class I’m referring to actually implements both the FieldEvents.BlurListener and the Button.ClickListener interfaces. So a call to Button’s addListener() is ambiguos.

Is there any chance to do what I’m trying to do? i.e.:

public class X implements FieldEvents.BlurListener, Button.ClickListener {

public void blur(FieldEvents.BlurEvent event) {

}

public void buttonClick(Button.ClickEvent event) {

}

}

and have this class added with addListener() to a button?

Thanks very much, Marco

Sure, you just have to cast to tell which addListener you want to call:

button.addListener((Button.ClickListener) this);

Hi Henri,

thanks for your answer, which obviously works (I made a very basic and silly question),

thanks, Marco

Or you could create separate listener classes that don’t implement more than one interface (I just don’t like casts (though I apparently do like parentheses)). If you do this as inner classes, you’ll use less memory by declaring them static:

public class MyMainClass {
    // etc
    
    static class MyListener implements etc {
    }
}

Cheers,
Bobby

Thanks Bobby for your answer, too, but I found myself more comfortable with the casting way (I do like having parenthesis :)).

Thanks, Marco