首页 > 解决方案 > Vaadin Maven 编译错误 (ComponentUtil.addListener))

问题描述

不幸的是,无法为我的 Vaadin 应用程序执行 maven 安装。我在 Eclipse 中没有错误。也可以通过 Eclipse 运行应用程序。但是 maven 安装总是在这个错误中运行:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project lunchlist: Compilation failure: Compilation failure: 
[ERROR] /C:/Users/thomas/workspace/test/src/main/java/TestView.java:[214,42] incompatible types: cannot infer type-variable(s) T
[ERROR]     (argument mismatch; cannot infer functional interface descriptor for com.vaadin.flow.component.ComponentEventListener<com.vaadin.flow.component.ClickEvent>)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

以下代码导致编译错误:

ComponentUtil.addListener(label, ClickEvent.class, e -> {
    xxxxx
});

有人有想法吗?提前致谢!:)

最好的问候,托马斯

标签: vaadinvaadin-flow

解决方案


ComponentEventListener您可以通过为听众添加 upcast 来解决此问题:

ComponentUtil.addListener(label, ClickEvent.class, 
    (ComponentEventListener)  e -> Notification.show("Clicked"));

推荐阅读