# javax.lang.model.type

***

**1. Get the type of a field**

```java
Field field = ...;
TypeMirror fieldType = field.getEnclosingElement().asType();
```

**2. Get the type of a method parameter**

```java
Method method = ...;
TypeMirror parameterType = method.getParameters().get(0).asType();
```

**3. Get the type of a method return value**

```java
Method method = ...;
TypeMirror returnType = method.getReturnType();
```

**4. Get the type of a class**

```java
Class<?> clazz = ...;
TypeMirror classType = TypeMirror.get(clazz);
```

**5. Get the type of an array**

```java
Class<?> clazz = ...;
TypeMirror arrayType = TypeMirror.get(clazz.getComponentType()).getArrayType();
```

**6. Get the type of a wildcard**

```java
TypeMirror wildcardType = TypeMirror.getWildcardType(WildcardType.Kind.UNBOUNDED);
```

**7. Get the type of a type variable**

```java
TypeVariable<?> typeVariable = ...;
TypeMirror typeVariableType = typeVariable.getLowerBound();
```

**8. Get the type of a capture variable**

```java
CaptureVariable variable = ...;
TypeMirror captureVariableType = variable.getType();
```

**9. Get the type of a generic method**

```java
Method genericMethod = ...;
TypeMirror genericMethodType = genericMethod.getGenericReturnType();
```

**10. Get the type of a generic class**

```java
Class<?> genericClass = ...;
TypeMirror genericClassType = TypeMirror.get(genericClass);
```

**11. Get the type of a generic interface**

```java
Interface genericInterface = ...;
TypeMirror genericInterfaceType = TypeMirror.get(genericInterface);
```

**12. Get the type of a parameterized type**

```java
Class<?> parameterizedClass = ...;
TypeMirror parameterizedType = TypeMirror.get(parameterizedClass);
```

**13. Get the type of a raw type**

```java
Class<?> rawType = ...;
TypeMirror rawType = TypeMirror.get(rawType);
```

**14. Get the type of an intersection type**

```java
IntersectionType intersectionType = ...;
TypeMirror intersectionTypeType = intersectionType.getConstituents().get(0);
```

**15. Get the type of an union type**

```java
UnionType unionType = ...;
TypeMirror unionTypeType = unionType.getConstituents().get(0);
```

**16. Get the type of a nested type**

```java
Class<?> nestedClass = ...;
TypeMirror nestedType = TypeMirror.get(nestedClass);
```

**17. Get the type of an annotation**

```java
Annotation annotation = ...;
TypeMirror annotationType = annotation.getAnnotationType();
```

**18. Get the type of an enum constant**

```java
EnumConstant enumConstant = ...;
TypeMirror enumConstantType = enumConstant.getType();
```

**19. Get the type of a package**

```java
Package pkg = ...;
TypeMirror packageType = TypeMirror.get(pkg);
```

**20. Get the type of a type parameter**

```java
TypeParameter typeParameter = ...;
TypeMirror typeParameterType = typeParameter.getBounds().get(0);
```

**21. Get the type of a method receiver**

```java
Method method = ...;
TypeMirror receiverType = method.getReceiverParameter().getType();
```

**22. Get the type of a method exception**

```java
Method method = ...;
TypeMirror exceptionType = method.getExceptionTypes().get(0);
```

**23. Get the type of a method type parameter**

```java
Method method = ...;
TypeMirror typeParameterType = method.getTypeParameters().get(0).asType();
```

**24. Get the type of a constructor argument**

```java
Constructor constructor = ...;
TypeMirror parameterType = constructor.getParameters().get(0).asType();
```

**25. Get the type of a constructor exception**

```java
Constructor constructor = ...;
TypeMirror exceptionType = constructor.getExceptionTypes().get(0);
```

**26. Get the type of a constructor type parameter**

```java
Constructor constructor = ...;
TypeMirror typeParameterType = constructor.getTypeParameters().get(0).asType();
```

**27. Get the type of a type cast**

```java
CastTree castTree = ...;
TypeMirror castType = castTree.getType();
```

**28. Get the type of an instanceof expression**

```java
InstanceOfTree instanceofTree = ...;
TypeMirror instanceofType = instanceofTree.getType();
```

**29. Get the type of a new array expression**

```java
NewArrayTree newArrayTree = ...;
TypeMirror arrayType = newArrayTree.getType();
```

**30. Get the type of a new class expression**

```java
NewClassTree newClassTree = ...;
TypeMirror newClassType = newClassTree.getType();
```

**31. Get the type of a parenthesized expression**

```java
ParenthesizedTree parenthesizedTree = ...;
TypeMirror parenthesizedType = parenthesizedTree.getType();
```

**32. Get the type of a switch statement**

```java
SwitchTree switchTree = ...;
TypeMirror switchType = switchTree.getExpression().getType();
```

**33. Get the type of a synchronized statement**

```java
SynchronizedTree synchronizedTree = ...;
TypeMirror synchronizedType = synchronizedTree.getExpression().getType();
```

**34. Get the type of a try statement**

```java
TryTree tryTree = ...;
TypeMirror tryType = tryTree.getExpression().getType();
```

**35. Get the type of a throw statement**

```java
ThrowTree throwTree = ...;
TypeMirror throwType = throwTree.getExpression().getType();
```

**36. Get the type of a while statement**

```java
WhileLoopTree whileLoopTree = ...;
TypeMirror whileType = whileLoopTree.getCondition().getType();
```

**37. Get the type of a do-while statement**

```java
DoWhileLoopTree doWhileLoopTree = ...;
TypeMirror doWhileType = doWhileLoopTree.getCondition().getType();
```

**38. Get the type of a for-each statement**

```java
EnhancedForTree enhancedForTree = ...;
TypeMirror forEachType = enhancedForTree.getVariable().getType();
```

**39. Get the type of a for statement**

```java
ForLoopTree forLoopTree = ...;
TypeMirror forType = forLoopTree.getCondition().getType();
```

**40. Get the type of a break statement**

```java
BreakTree breakTree = ...;
TypeMirror breakType = breakTree.getEnclosingStatement().getType();
```

**41. Get the type of a continue statement**

```java
ContinueTree continueTree = ...;
TypeMirror continueType = continueTree.getEnclosingStatement().getType();
```

**42. Get the type of a return statement**

```java
ReturnTree returnTree = ...;
TypeMirror returnType = returnTree.getExpression().getType();
```

**43. Get the type of a variable**

```java
VariableTree variableTree = ...;
TypeMirror variableType = variableTree.getType();
```

**44. Get the type of an expression statement**

```java
ExpressionStatementTree expressionStatementTree = ...;
TypeMirror expressionType = expressionStatementTree.getExpression().getType();
```

**45. Get the type of a block statement**

```java
BlockTree blockTree = ...;
TypeMirror blockType = blockTree.getStatements().get(0).getType();
```

**46. Get the type of an if statement**

```java
IfTree ifTree = ...;
TypeMirror ifType = ifTree.getCondition().getType();
```

**47. Get the type of an else if statement**

```java
IfTree elseIfTree = ...;
TypeMirror elseIfType = elseIfTree.getCondition().getType();
```

**48. Get the type of an else statement**

```java
ElseTree elseTree = ...;
TypeMirror elseType = elseTree.getStatements().get(0).getType();
```

**49. Get the type of a switch-case statement**

```java
CaseTree caseTree = ...;
TypeMirror caseType = caseTree.getExpression().getType();
```

**50. Get the type of a switch-default statement**

```java
DefaultTree defaultTree = ...;
TypeMirror defaultType = defaultTree.getStatements().get(0).getType();
```
