Java/Java 기타

자바에서 @SupressWarnings 사용하는 한 가지 방법

kimc 2022. 5. 21. 10:07

```

자바에서 @SupressWarnings 사용하는 한 가지 방법

```

이번 글을 통해 배워갈 내용

  1. @SupressWarnings 정의
  2. @SupressWarnings Annotation 예시

 


 

Annotation이란

https://codemasterkimc.tistory.com/397

 

자바 Annotation의 정의와 종류 그리고 사용 예시

``` Annotation의 정의 Annotation의 종류 Annotation의 사용 예시 ``` 이번 글을 통해 배워갈 내용  Annotation의 정의  Annotation의 종류  Annotation의 사용 예시 Annotation의 정의 Annotation은 메타데..

codemasterkimc.tistory.com

 

 

@SupressWarnings 정의

Java 1.5부터 지원되는 기능으로서 

@SupressWarnings을 사용해서 컴파일러 경고를 무시하게 해 줍니다.

 

@SupressWarnings Annotation 예시

 

 

Animal interface

public interface Animal {
    @Deprecated
    void hello();
}

 

Animal interface를 구현한 Cat 클래스

public class Cat implements Animal{
    @Override
    public void hello() {
        System.out.print("hey");
    }
}

 

고양이를 실행하는 App 클래스

public class App {
    @SuppressWarnings({"unchecked", "deprecation"})
    public static void main(String[] args) {
        Animal myCat = new Cat();
        myCat.hello();
    }
}

 

Deprecated 된 hello method의 경우

main에서 deprecation을 suppressWarning 해주지 않으면

경고 문구를 띄웁니다.

 

 

 

참조

https://www.baeldung.com/java-suppresswarnings

 

Java @SuppressWarnings Annotation | Baeldung

Learn how to use the @SuppressWarnings annotation

www.baeldung.com

https://www.ibm.com/docs/ko/radfws/9.6.1?topic=code-excluding-warnings 

 

읽어주셔서 감사합니다

 

무엇인가 얻어가셨기를 바라며

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

728x90