Ambiguous method overloading for method com.vaadin.ui.Tree#addListener

Simplified version of my code…


class TreePanel extends Panel implements Property.ValueChangeListener, Tree.ExpandListener {

   public TreePanel() {

       tree = new Tree()
       tree.addListener(this)

   }

   void nodeExpand(ExpandEvent event) {
    
   }

   void valueChange(ValueChangeEvent event) {
    
   }
}

And I’m getting the following exception:

I am using this in a grails application, so it is groovy code. Curious to know if that has something to do with it because of it’s dynamic nature of things. Otherwise, not sure what is going as as the Tree demo on the vaadin site does something quite similar.


// Add Valuechangelistener and Actionhandler
tree.addListener(this);

You have to cast your parameter because Tree has both addListener(ExpandListener listener) and addListener(ValueChangeListener listener) methods and your class implements these interfaces.

So try tree.addListener((ValueChangeListener) this); or tree.addListener((ExpandListener) this);

Thanks Henri! Out of curiosity, is there a reason the Vaadin Tree single selection demo doesn’t need to do the casting?

Because the class being registered as a listener only implements one of the listener interfaces.

Ok, I see now. The comment in the code is confusing. Thanks for clearing that up.