Java 8使用lambda将clickListener作为参数传递

Java 8使用lambda将clickListener作为参数传递,java,lambda,java-8,vaadin,Java,Lambda,Java 8,Vaadin,我想创建一个方法,在vaadin中用参数创建一个按钮 private void addButton(Button button, String toolTip, FontAwesome fontAwesome, ... clickEvent){ button = new Button(fontAwesome); button.setDescription(toolTip); button.setEnabled(false); but

我想创建一个方法,在vaadin中用参数创建一个按钮

private void addButton(Button button, String toolTip, FontAwesome fontAwesome, ... clickEvent){
        button = new Button(fontAwesome);
        button.setDescription(toolTip);
        button.setEnabled(false);
        button.addClickListener(event -> clickEvent);
    }
电话:

addButton(newButton, "My test Button", FontAwesome.PLUS_SQUARE, someObject.do())
如何使用lambda将clickListener设置为参数

private void addButton(Button button, String toolTip, FontAwesome fontAwesome, Button.ClickListener clickEvent){
    button = new Button(fontAwesome);
    button.setDescription(toolTip);
    button.setEnabled(false);
    button.addClickListener(clickEvent);
}
然后,您将像下面这样调用您的方法
addButton(newButton,“Test”,o,evt->someMethod())

[编辑]:虽然我认为它回答了您的问题,但请注意,
新按钮
将无法从方法调用方访问,这可能是代码中的一个错误,您应该考虑返回该按钮