com.fasterxml.classmate
Java API reference for the package com.fasterxml.classmate.
Public API
Class: TypeResolver
Canonical path: com.fasterxml.classmate.TypeResolver
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signature
public class TypeResolver {}
Summary
Object that is used for resolving generic type information of a class so that it is accessible using simple API. Resolved types are also starting point for accessing resolved (generics aware) return and argument types of class members (methods, fields, constructors). <p> Note that resolver instances are stateful in that resolvers cache resolved types for efficiency. Since this is internal state and not directly visible to callers, access to state is fully synchronized so that access from multiple threads is safe.
Constructor: TypeResolver
Canonical path: com.fasterxml.classmate.TypeResolver.TypeResolver
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signature
public TypeResolver() {}
Method: arrayType
Canonical path: com.fasterxml.classmate.TypeResolver.arrayType
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signature
public ResolvedArrayType arrayType(ResolvedType elementType) {}
Summary
Factory method for constructing array type of given element type.
Behavior
The method constructs a new ResolvedArrayType using the class of an empty array instance of the element type, empty type bindings, and the provided element type.
Parameters
- elementType: The element type of the array to be constructed.
Returns
- Return value 1: A resolved array type of the given element type.
Method: isSelfReference
Canonical path: com.fasterxml.classmate.TypeResolver.isSelfReference
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signature
public static boolean isSelfReference(ResolvedType type) {}
Summary
Helper method that can be used to checked whether given resolved type (with erased type of ) is a placeholder for "self-reference"; these are nasty recursive ("self") types needed with some interfaces
Behavior
The method checks if the provided resolved type is an instance of ResolvedRecursiveType.
Parameters
- type: The resolved type to check.
Returns
- Return value 1: True if the type is a placeholder for a self-reference, false otherwise.
Method: resolve
Canonical path: com.fasterxml.classmate.TypeResolver.resolve
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signatures
Overload 1
public ResolvedType resolve(GenericType<?> generic) {}
Summary
Factory method for resolving given generic type, defined by using sub-class instance of {@link GenericType}
Behavior
The method resolves the generic type by finding the supertype GenericType for the provided instance's class and extracting its first type parameter.
Parameters
- generic: A sub-class instance of GenericType defining the type to resolve.
Returns
- Return value 1: The resolved type extracted from the GenericType parameterization.
Overload 2
public ResolvedType resolve(Type jdkType, TypeBindings typeBindings) {}
Summary
Factory method for resolving specified Java {@link java.lang.reflect.Type}, given {@link TypeBindings} needed to resolve any type variables. <p> Use of this method is discouraged (use if and only if you really know what you are doing!); but if used, type bindings passed should come from {@link ResolvedType} instance of declaring class (or interface).
Behavior
The method resolves the JDK type by delegating to an internal method with the provided type bindings.
Parameters
- jdkType: The Java reflect type to resolve.
- typeBindings: Type bindings used to resolve type variables, typically from the declaring class.
Returns
- Return value 1: The resolved type.
Overload 3
public ResolvedType resolve(Class<?> rawType) {}
Summary
Factory method for resolving a type-erased class; in this case any generic type information has to come from super-types (via inheritance).
Behavior
The method resolves the class using empty type bindings.
Parameters
- rawType: The type-erased class to resolve.
Returns
- Return value 1: The resolved type, with generic information derived from super-types.
Overload 4
public ResolvedType resolve(Class<?> type, Class<?>... typeParameters) {}
Summary
Factory method for resolving given type (specified by type-erased class), using specified types as type parameters. Sample usage would be:
Behavior
which would be equivalent to
Parameters
- type: The type-erased class to be resolved.
- typeParameters: Classes to be used as type parameters for the resolved type.
Returns
- Return value 1: The resolved type with the specified type parameters.
Overload 5
public ResolvedType resolve(Class<?> type, ResolvedType... typeParameters) {}
Summary
Factory method for resolving given type (specified by type-erased class), using specified types as type parameters. Sample usage would be:
Behavior
which would be equivalent to
Parameters
- type: The type-erased class to be resolved.
- typeParameters: Resolved types to be used as type parameters.
Returns
- Return value 1: The resolved type with the specified type parameters.
Method: resolveSubtype
Canonical path: com.fasterxml.classmate.TypeResolver.resolveSubtype
Declared in: src/main/java/com/fasterxml/classmate/TypeResolver.java
Signature
public ResolvedType resolveSubtype(ResolvedType supertype, Class<?> subtype)
throws IllegalArgumentException, UnsupportedOperationException {}
Summary
Factory method for constructing sub-classing specified type; class specified as sub-class must be compatible according to basic Java inheritance rules (subtype must propery extend or implement specified supertype). <p> A typical use case here is to refine a generic type; for example, given that we have generic type like , but we want a more specific implementation type like class but with same parameterization (here just ), we could achieve it by:
Behavior
(in this case, it would have been simpler to resolve directly; but in some cases we are handled supertype and want to refine it, in which case steps would be the same but separated by other code) <p> Note that this method will fail if extension can not succeed; either because this type is not extendable (sub-classable) -- which is true for primitive and array types -- or because given class is not a subtype of this type. To check whether subtyping could succeed, you can call {@link ResolvedType#canCreateSubtypes()} to see if supertype can ever be extended.
Parameters
- supertype: Type to subtype (extend)
- subtype: The type-erased sub-class or sub-interface to resolve.
Returns
- Return value 1: Resolved subtype
Errors
IllegalArgumentException If this type can be extended in general, but not into specified sub-class UnsupportedOperationException If this type can not be sub-classed