Package jakarta.ws.rs.core
Class GenericType<T>
java.lang.Object
jakarta.ws.rs.core.GenericType<T>
- Type Parameters:
T
- the generic type parameter.
Represents a generic message entity type
T
.
Supports in-line instantiation of objects that represent generic types with actual type parameters. An object that
represents any parameterized type may be obtained by sub-classing GenericType
. Alternatively, an object
representing a concrete parameterized type can be created using a GenericType(java.lang.reflect.Type)
and
manually specifying the actual (parameterized) type
.
For example:
GenericType<List<String>> stringListType = new GenericType<List<String>>() { };
Or:
public class MyGenericType extends GenericType<List<String>> { ... } ... MyGenericType stringListType = new MyGenericType();
Note that due to the Java type erasure limitations the parameterized type information must be specified on a
subclass, not just during the instance creation. For example, the following case would throw an
IllegalArgumentException
:
public class MyGenericType<T> extends GenericType<T> { ... } ... // The type is only specified on instance, not in a sub-class MyGenericType<List<String>> stringListType = new MyGenericType<List<String>>();
- Since:
- 2.0
-
Constructor Summary
ModifierConstructorDescriptionprotected
Constructs a new generic type, deriving the generic type and class from type parameter.GenericType
(Type genericType) Constructs a new generic type, supplying the generic type information and deriving the class. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static GenericType
forInstance
(Object instance) Create ageneric type
from a Javainstance
.final Class<?>
Returns the object representing the class or interface that declared the type represented by this generic type instance.final Type
getType()
Retrieve the type represented by the generic type instance.int
hashCode()
toString()
-
Constructor Details
-
GenericType
protected GenericType()Constructs a new generic type, deriving the generic type and class from type parameter. Note that this constructor is protected, users should create a (usually anonymous) subclass as shown above.- Throws:
IllegalArgumentException
- in case the generic type parameter value is not provided by any of the subclasses.
-
GenericType
Constructs a new generic type, supplying the generic type information and deriving the class.- Parameters:
genericType
- the generic type.- Throws:
IllegalArgumentException
- if genericType isnull
or not an instance ofClass
orParameterizedType
whose raw type is an instance ofClass
.
-
-
Method Details
-
forInstance
Create ageneric type
from a Javainstance
.If the supplied instance is a
GenericEntity
, the generic type will be computed using theGenericEntity.getType()
. Otherwiseinstance.getClass()
will be used.- Parameters:
instance
- Java instance for which theGenericType
description should be created.- Returns:
GenericType
describing the Javainstance
.- Since:
- 2.1
-
getType
Retrieve the type represented by the generic type instance.- Returns:
- the actual type represented by this generic type instance.
-
getRawType
Returns the object representing the class or interface that declared the type represented by this generic type instance.- Returns:
- the class or interface that declared the type represented by this generic type instance.
-
equals
-
hashCode
public int hashCode() -
toString
-