UnionType — 유니온 타입 인터페이스
UnionType — 유니온 타입 인터페이스
UnionType는 유니온 타입(union type)을 나타내는 인터페이스예요. 유니온 타입은 멀티캐치(multicatch)에서 예외 매개변수를 여러 타입의 유니온으로 명시적으로 선언할 때 발생할 수 있어요. 예를 들어:
catch (IOException | SQLException e) {
// ...
}
이 경우 e의 타입은 IOException과 SQLException의 유니온 타입이에요. TypeMirror를 확장해요.
본문
선언은 다음과 같아요.
public interface UnionType extends TypeMirror
주요 메서드는 다음과 같아요.
| Modifier and Type | Method | 설명 |
|---|---|---|
List<? extends TypeMirror> |
getAlternatives() |
이 유니온 타입을 구성하는 대안(alternative) 타입들을 반환해요. |
UnionType ut = (UnionType) exceptionParameterMirror.asType();
List<? extends TypeMirror> alts = ut.getAlternatives(); // [IOException, SQLException]
getAlternatives()는 유니온을 구성하는 각 타입 목록을 돌려줘요. getKind()는 TypeKind.UNION을 반환해요. Since: 1.7.