【问题标题】:Can not compiler Java 10 feature无法编译 Java 10 功能
【发布时间】:2019-09-26 18:37:39
【问题描述】:

我在我的源代码中使用了 Java 10 API,当我尝试使用 maven 和 IDEA 编译这段代码时,它会抛出一个错误:

// I use this Java 10 API
URLDecoder.decode(query, StandardCharsets.UTF_8)
// throw this error
Error:(10, 73) java: incompatible types: java.nio.charset.Charset cannot be converted to java.lang.String

我的环境:

  • JDK 10

  • maven:3.6

  • 想法

如果我删除这个 API 我很好。

而且我确实遵循以下规则:

  1. 为 pom 添加编译器选项
 <maven.compiler.target>10</maven.compiler.target>
 <maven.compiler.source>10</maven.compiler.source>
  1. 将 IDEA 语言级别更改为 java10

    文件 -> 项目结构 -> 模块 -> 语言级别

以上两个不起作用。

【问题讨论】:

  • 试试这个:StandardCharsets.UTF_8.name()
  • 如果你解决了这个问题,请分享给我。因为两天前我还没有解决这个问题。
  • 我解决了这个问题。 stackoverflow.com/a/55980478/10995103 还是谢谢

标签: maven intellij-idea javac


【解决方案1】:

我根据你的描述创建了sample project,无法重现问题。

它在IntelliJ IDEAcommand line Maven 中编译时都没有错误。

如果您仍然可以重现该问题,请contact support 附上Minimal, Complete, and Verifiable example 并指定您的 IntelliJ IDEA 版本。

【讨论】:

  • 不知何故它在本地也适用于我,但在管道环境中失败
  • @fireball.1 :我遇到了同样的问题 - 您可能在本地没有相同的 JDK。我使用hub.docker.com/_/maven 在本地运行 maven,其版本与 GitHub Actions 中使用的版本相同。如果您想在本地测试 GitHub Actions,github.com/nektos/act 是您的朋友。
猜你喜欢
  • 2020-04-28
  • 1970-01-01
  • 1970-01-01
  • 2018-08-30
  • 2012-11-10
  • 2015-11-10
  • 1970-01-01
  • 2019-01-08
相关资源
最近更新 更多