【问题标题】:Vaadin Maven Compile Error (ComponentUtil.addListener))Vaadin Maven 编译错误 (ComponentUtil.addListener))
【发布时间】:2021-05-16 07:32:25
【问题描述】:

很遗憾,无法为我的 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
});

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

最好的问候, 托马斯

【问题讨论】:

  • 您的 maven 命令是否使用与 eclipse 相同版本的 java 来编译应用程序的源代码?
  • 您好!我不知道。如何识别/更改 Maven 的 Java 版本(在 Eclipse 中)?我在 Eclipse 中通过右键单击执行 maven 命令。问候,托马斯
  • 我可以在 IntelliJ 中重现它,因为它在类中没有显示错误,但是运行、构建或 mvn install 显示该错误。尝试使用 AdoptOpenJDK 11.0.11 和 1.8.0_265。通过mvn -version可以看到Maven使用的是哪个版本,应该是JAVA_HOME环境变量指向的版本。
  • Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f) Java 版本:15.0.2,供应商:Oracle Corporation,运行时:C:\Program Files\Java\jdk-15.0.2 默认语言环境:de_DE,平台编码: UTF-8 操作系统名称:“windows 10”,版本:“10.0”,arch:“amd64”,family:“windows” 与在 Eclipse 中编译源代码的 java 版本相同

标签: vaadin vaadin-flow


【解决方案1】:

您可以通过向ComponentEventListener 为您的听众添加向上转换来解决此问题:

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

【讨论】:

  • 不幸的是,这并不能解决错误。还是一样的信息...
  • 而您只是添加(ComponentEventListener),而不是例如(ComponentEventListener&lt;ClickEvent&gt;)?对我来说,这解决了这个问题,用三种不同的 JDK 进行了测试。
  • 是的,但我会收到其他消息:[214,94] type argument com.vaadin.flow.component.ClickEvent is not within bounds of type-variable T
  • 这样就可以了....感谢您的帮助! ComponentUtil.addListener(imprint, ClickEvent.class, new ComponentEventListener() { public void onComponentEvent(ComponentEvent event) { xxxx } });
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-28
  • 2015-08-30
  • 1970-01-01
  • 1970-01-01
  • 2012-01-29
相关资源
最近更新 更多