Interface Type

All Superinterfaces:
AnnotationTarget
All Known Subinterfaces:
ArrayType, ClassType, ParameterizedType, PrimitiveType, TypeVariable, VoidType, WildcardType

public interface Type extends AnnotationTarget
A type is used in a program source code, but does not have to be declared anywhere.

For example, the int type exists even if it is not declared in any Java source file, while the java.lang.String type is declared by the class of the same name. Array types, such as int[] or String[][], are not declared anywhere either, but their element types may be. A generic class, such as java.util.List, declares a raw type of the same name, but it does not declare the parameterized types, such as List<String>. Parameterized types are created by applying type arguments to generic classes. For example, the List<String> type is created by applying String to List<T>.

Types occur on many places. A field has a type, a method has a return type, a method parameter has a type, even the extends clause in a class declaration contains a type. Occurences of types may be annotated.

Types are:

  • the void pseudo-type
  • a primitive type, such as int
  • a class type, such as String
  • an array type, such as int[] or String[][]
  • a parameterized type, such as List<String>
  • a type variable, such as T when used in a class that declares a type parameter T
  • a wildcard type, such as the type argument in List<? extends Number>
Class types and parameterized types allow obtaining their class declarations.