Intellij – 无法使用较新的Java 8类 – 错误:“API的用法记录为@since 1.6+

来源:互联网 发布:网络暴力的调查报告 编辑:程序博客网 时间:2024/06/05 19:06

问题描述

我试图在我的java 8代码库中使用java.lang.function.Function,但是我在Intellij中收到以下错误。

Usage of API documented as @since 1.6+ This inspection finds all usages of methods that have @since tag in their documentation. This may be useful when development is performed under newer SDK version as the target platform for production

我似乎有正确的项目和编译器设置

项目设置:

Project Settings -> Project -> Project SDK = Java 1.8Project Settings -> Project -> Project Language Level = 8 - Lambdas, Type Annotations etc

编译器设置:

Build, Execution, Deployment -> Compiler -> Java Compiler -> Project Bytecode Version : 1.8Build, Execution, Deployment -> Compiler -> Java Compiler -> Per module Bytecode Version -> Target Bytecode Version : 1.8

问题是什么?

最佳解决方案

根据Bastien Jansen评论编辑了答案。

似乎有另一个影响编译器级别的项目设置。这个问题的一个微妙的指示是编译器开始抱怨源和目标java版本与您在编译代码时指定的版本不同

Warning:java: source value 1.5 is obsolete and will be removed in a future releaseWarning:java: target value 1.5 is obsolete and will be removed in a future releaseWarning:java: To suppress warnings about obsolete options, use -Xlint:-options.

要摆脱这一点,你需要开放

File -> Project Structure -> Project Settings -> Modules -> "Your Module Name" -> Sources -> Language Level

并将其改为所需的级别,即1.8或默认项目默认语言级别

次佳解决方案

如果您使用maven,然后在配置pom.xml文件中添加以下行,然后从maven重新导入或构建它。

<build>    <plugins>        <plugin>            <groupId>org.apache.maven.plugins</groupId>            <artifactId>maven-compiler-plugin</artifactId>            <version>3.3</version>            <configuration>                <source>1.8</source>                <target>1.8</target>            </configuration>        </plugin>    </plugins></build>

否则,从下面的路径中选择java编译器和语言级别。

文件>项目结构>项目设置>模块>你的模块名称>来源>语言水平>选择你需要的那个。

intellij-idea,java-8

从这里改变语言水平: –

intellij-idea,java-8

第三种解决方案

实际上,如果您使用Maven并且您的pom.xml项目属性配置正确

<project xmlns="...> ....<properties>         <maven.compiler.source>1.8</maven.compiler.source>         <maven.compiler.target>1.8</maven.compiler.target></properties>...</project

您可以将Maven参数重新导入到intellij-idea项目中 – 右键单击​​项目根目录,然后在底部的Maven -> Reimport

intellij-idea,java-8

参考文献

  • Intellij – Unable to use newer Java 8 classes – Error : “Usage of API documented as @since 1.6+..”


阅读全文
0 0
原创粉丝点击