programing tip

-Xlint : unchecked로 어떻게 컴파일합니까?

itbloger 2020. 11. 14. 09:59
반응형

-Xlint : unchecked로 어떻게 컴파일합니까?


코드를 컴파일 할 때 메시지가 나타납니다.

Note: H:\Project2\MyGui2.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

어떻게 다시 컴파일 -Xlint:unchecked합니까?


javac의 명령 줄에서 지정합니다.

javac -Xlint : 선택 취소

또는 Ant를 사용하는 경우 javac 대상을 수정하십시오.

  <javac ...>
    <compilerarg value="-Xlint"/>
  </javac> 

Maven을 사용하는 경우 다음에서 구성하십시오. maven-compiler-plugin

<compilerArgument>-Xlint:unchecked</compilerArgument>

들어 IntelliJ에 13.1 로 이동 File> - Settings-> Project Settings-> Compiler> - Java Compiler을 위해, 그리고에 오른쪽 Additional command line parameters입력 "-Xlint:unchecked".


gradle 프로젝트에서 다음과 같은 방법으로이 컴파일 매개 변수를 추가 할 수 있습니다.

gradle.projectsEvaluated {
    tasks.withType(JavaCompile) {
        options.compilerArgs << "-Xlint:unchecked"
    }
}

이상하게 들리지만 이것이 귀하의 문제라고 확신합니다.

MyGui.java 어딘가에서 유형을 지정하지 않고 일반 컬렉션을 사용하고 있습니다. 예를 들어 어딘가에서 ArrayList를 사용하는 경우 다음을 수행합니다.

List list = new ArrayList();

이 작업을 수행해야하는 경우 :

List<String> list = new ArrayList<String>();

gradle에 대한 또 다른 방법이 있습니다.

compileJava {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}

CMD에서 다음을 작성하십시오.

javac -Xlint:unchecked MyGui2.java

확인되지 않았거나 안전하지 않은 작업 목록이 표시됩니다.


NetBeans와 같은 IDE로 작업하는 경우 Xlint:unchecked프로젝트 속성에 컴파일러 옵션을 지정할 수 있습니다 .

프로젝트 창으로 이동하여 프로젝트를 마우스 오른쪽 버튼으로 클릭 한 다음을 클릭하십시오 Properties.

나타나는 창에서 Compiling범주를 검색하고 레이블이 지정된 텍스트 상자 Additional Compiler Options에서 Xlint:unchecked옵션을 설정합니다 .

따라서 프로젝트를 컴파일 할 때마다 설정이 유지됩니다.


Gradle 컴파일러 인수를 지정하는 더 깨끗한 방법은 다음과 같습니다.

compileJava.options.compilerArgs = [ '-Xlint : unchecked', '-Xlint : deprecation']


Android Studio의 build.gradle경우 allprojects블록 내의 최상위 파일에 다음을 추가하십시오.

tasks.withType(JavaCompile) {
    options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" 
}

other way to compile using -Xlint:unchecked through command line

javac abc.java -Xlint:unchecked

it will show the unchecked and unsafe warnings.


FYI getting to these settings has changed for IntelliJ 15, new and improved for even deeper burial!

Now it's: File > Other Settings > Default Settings > 'Build, Execution, Deployment' > Compiler > Java Compiler

And in Additional command line parameters, same as before, write "-Xlint:unchecked".

참고URL : https://stackoverflow.com/questions/8215781/how-do-i-compile-with-xlintunchecked

반응형