IntersectionType — 교차 타입 인터페이스

IntersectionType — 교차 타입 인터페이스

IntersectionType는 교차 타입(intersection type)을 나타내는 인터페이스예요. 교차 타입은 프로그램에서 암묵적으로나 명시적으로 선언될 수 있어요. 예를 들어 타입 매개변수의 경계 <T extends Number & Runnable>는 (암묵적) 교차 타입이에요. 이는 NumberRunnable을 경계로 갖는 IntersectionType으로 표현돼요.

구현 노트: 참조 구현에서 IntersectionType은 캐스트(cast) 표현식의 명시적 대상 타입을 모델링하는 데 쓰여요.

출처: Java API Reference

본문

선언은 다음과 같아요.

public interface IntersectionType extends TypeMirror

주요 메서드는 다음과 같아요.

Modifier and Type Method 설명
List<? extends TypeMirror> getBounds() 이 교차 타입을 구성하는 경계들의 목록을 반환해요.
// <T extends Number & Runnable> 의 경계
IntersectionType it = (IntersectionType) typeVariable.getUpperBound();
List<? extends TypeMirror> bounds = it.getBounds(); // [Number, Runnable]

교차 타입의 경계 목록은 getBounds()로 얻을 수 있어요. getKind()TypeKind.INTERSECTION을 반환해요. Since: 1.8.

더 알아보기 (Learn more)

Java 공식 API