Intellij-최신 Java 8 클래스를 사용할 수 없음-오류 :“@since 1.6 이상으로 문서화 된 API 사용 ..”
java.lang.function.Function
Java 8 코드베이스에서 를 사용하려고하는데 Intellij에서 다음과 같은 오류가 계속 발생합니다.
@since 1.6 이상으로 문서화 된 API 사용법이 검사는 문서에 @since 태그가있는 모든 메소드 사용법을 찾습니다. 새로운 SDK 버전에서 개발 대상 플랫폼으로 개발할 때 유용 할 수 있습니다.
프로젝트 및 컴파일러 설정이 올바른 것 같습니다
프로젝트 설정 : (파일-> 프로젝트 구조)
Project Settings -> Project -> Project SDK = Java 1.8
Project Settings -> Project -> Project Language Level = 8 - Lambdas, Type Annotations etc
컴파일러 설정 : (파일-> 설정)
Build, Execution, Deployment -> Compiler -> Java Compiler -> Project Bytecode Version : 1.8
Build, Execution, Deployment -> Compiler -> Java Compiler -> Per module Bytecode Version -> Target Bytecode Version : 1.8
무엇이 문제입니까?
Bastien Jansen 의견을 바탕으로 답변을 편집했습니다.
컴파일러 수준에 영향을주는 다른 프로젝트 설정이있는 것 같습니다. 이 문제의 미묘한 표시는 컴파일러가 소스를 불평하기 시작하고 코드를 컴파일하는 동안 지정한 Java 버전과 대상 Java 버전이 다르다는 것입니다
Warning:java: source value 1.5 is obsolete and will be removed in a future release
Warning:java: target value 1.5 is obsolete and will be removed in a future release
Warning: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 컴파일러 및 언어 레벨을 선택하십시오.
파일> 프로젝트 구조> 프로젝트 설정> 모듈> 모듈 이름> 소스> 언어 레벨> 필요한 것을 선택하십시오.
여기에서 언어 레벨을 변경하십시오 :-
실제로 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
하단에 있습니다.
방금 다음과 같이 수정했습니다.
프로젝트를 마우스 오른쪽 버튼으로 클릭-> 모듈 설정 열기-> 모듈-> 소스-> 8 이상
그리고
여전히 오류가 발생하고 maven을 사용 하는 경우 빌드 구성을 다음에 추가해야합니다 pom.xml
.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
파일> 설정> 빌드, 실행, 배포> Java 컴파일러
대상 바이트 코드 버전을 작업중인 모듈의 1.8로 변경하십시오.
Maven을 사용하는 경우
최상위 프로젝트 노드 아래의 pom.xml에 컴파일러 플러그인을 추가하십시오.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
If you are using Gradle, don't forget to make sure the following is set to 1.8 and not 1.5 (for instance for some bizarre reason in Intelij it defaults to 1.5) so no matter what you do at the project level to set the compiler compatibility level, this setting will cause it to continue giving you trouble with Java 8 features that it would not recognize:
version '1.0-SNAPSHOT'
apply plugin: 'groovy'
apply plugin: 'java'
sourceCompatibility = 1.8
Maybe your config of repository has properties include compiler Version. examine settings.xml
file.
<jdk>1.8</jdk>
</activation>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
There is one other place that might be causing this issue, regardless of whether or not you are using Maven or Gradle.
In Settings | Editor | Inspections | Java language level migration aids | Usages of API which isn't available at the configured language level
, the default (I believe) is set to Respecting to project language level settings
, but it can be set to Higher than:
, which ignores project settings.
다른 답변의 지침을 따르고 프로젝트의 언어 수준을 8로 설정했지만 검사가로 설정되어 있으면 Higher than: 7
IDEA는 여전히 적합합니다.
'Programming' 카테고리의 다른 글
위도 / 경도는 가장 가까운 위도 / 경도를 찾습니다-복잡한 SQL 또는 복잡한 계산 (0) | 2020.06.01 |
---|---|
자바 스크립트에서 HTML 특수 문자를 이스케이프 처리 할 수 있습니까? (0) | 2020.06.01 |
SQL Server 로그인이 이미 있는지 확인 (0) | 2020.06.01 |
UITableView가 ReloadData를 완료 한 시점을 알리는 방법? (0) | 2020.06.01 |
underscore.js를 사용하여 asc 및 desc 정렬을 수행하려면 어떻게해야합니까? (0) | 2020.06.01 |