• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

콜백 패턴 반환 타입 T가 두번 쓰이는 이유

24.03.09 08:16 작성 조회수 159

1

public class TraceTemplate {

    private final LogTrace trace;

    public TraceTemplate(LogTrace trace) {
        this.trace = trace;
    }


    public <T> T excute(String message, TraceCallBack<T> callback){

        TraceStatus status = null;
        try {
            status = trace.begin(message);
            //로직 호출
            T result = callback.call();
            trace.end(status);
            return result;
        } catch (Exception e) {
            trace.exception(status, e);
            throw e;
        }
    }
}

 

위 콜백 템플릿 에서 메서드 반환이 T 제네릭인건 이해가 되는데

왜 반환이 T가 2번 쓰이는걸까요?

답변 1

답변을 작성해보세요.

0

David님의 프로필

David

2024.03.10

안녕하세요. JunSuPark님, 공식 서포터즈 David입니다.

아래 글에서 "제네릭 메서드" 파트를 참고해 주세요:)

https://inpa.tistory.com/entry/JAVA-%E2%98%95-%EC%A0%9C%EB%84%A4%EB%A6%ADGenerics-%EA%B0%9C%EB%85%90-%EB%AC%B8%EB%B2%95-%EC%A0%95%EB%B3%B5%ED%95%98%EA%B8%B0

감사합니다.