DeclaredType — 선언 타입 인터페이스
DeclaredType — 선언 타입 인터페이스
DeclaredType는 선언 타입(declared type), 즉 클래스 타입 또는 인터페이스 타입을 나타내는 인터페이스예요. java.util.Set<String> 같은 매개변수화 타입과 원시(raw) 타입을 모두 포함해요.
TypeElement가 클래스나 인터페이스 요소를 나타내는 반면, DeclaredType는 클래스나 인터페이스 타입을 나타내며, 후자는 전자의 사용(또는 호출)이에요. 이 구분에 대한 자세한 내용은 TypeElement를 참고해요. 선언 타입의 슈퍼타입(클래스·인터페이스 타입 모두)은 Types.directSupertypes(TypeMirror)로 찾을 수 있어요. 이 메서드는 타입 인자를 치환한 슈퍼타입을 반환해요.
본문
하위 인터페이스로 ErrorType이 있어요. 선언은 다음과 같아요.
public interface DeclaredType extends ReferenceType
주요 메서드는 다음과 같아요.
| Modifier and Type | Method | 설명 |
|---|---|---|
Element |
asElement() |
이 타입에 대응하는 요소를 반환해요. |
TypeMirror |
getEnclosingType() |
가장 안쪽 감싸는 인스턴스의 타입을 반환하고, 감싸는 인스턴스가 없으면 kind NONE인 NoType을 반환해요. |
List<? extends TypeMirror> |
getTypeArguments() |
이 타입의 실제 타입 인자들을 반환해요. |
DeclaredType set = (DeclaredType) typeMirrorOfSet;
TypeElement e = (TypeElement) set.asElement(); // java.util.Set
List<? extends TypeMirror> args = set.getTypeArguments(); // [String] 등
getTypeArguments()는 Set<String>의 String 같은 실제 타입 인자를 돌려주고, asElement()는 그 타입을 선언한 요소를 돌려줘요. Since: 1.6.