Java/Java 기타

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

kimc 2022. 5. 21. 00:50

```

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

```

이번 글을 통해 배워갈 내용

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

 


 

Annotation이란

https://codemasterkimc.tistory.com/397

 

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

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

codemasterkimc.tistory.com

 

 

@Deprecated 정의

@Deprecated를 사용해서 다른 개발자들에게 해당되는 Method, field, constructor 등이 더 이상 사용되지 않는다는 것을 알려줍니다.

 

@Deprecated Annotation 예시

 

Animal interface

public interface Animal {
    public void hello();
}

 

Animal interface를 구현한 Cat 클래스

/*
고양이보다 개를 더 좋아합니다.
따라서 고양이 클래스를 안쓸 예정입니다.
 */
@Deprecated(since = "1.9", forRemoval = true)
public class Cat implements Animal{
    @Override
    public void hello() {
        System.out.print("hey");
    }
}

 

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

public class App {
    public static void main(String[] args) {
        Animal myCat = new Cat();
        myCat.hello();
    }
}

 

@Deprecated(since = "dog", forRemoval = true)에서 forRemoval = true인 경우

인텔리제이 같은 IDE에서는

아래에서 보시는 것과 같이 빨간 줄이 있습니다.

 

@Deprecated 인경우

한 줄만 있습니다.

 

참조

https://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/deprecation/deprecation.html

 

How and When to Deprecate APIs

How and When To Deprecate APIs You may have heard the term, "self-deprecating humor," or humor that minimizes the speaker's importance. A deprecated class or method is like that. It is no longer important. It is so unimportant, in fact, that you should no

docs.oracle.com

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

 

Java @Deprecated Annotation | Baeldung

Learn how to mark APIs as deprecated in Java

www.baeldung.com

읽어주셔서 감사합니다

 

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

 

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

 


 

728x90