- java.lang.Object
-
- javax.ws.rs.core.GenericType<T>
-
- Type Parameters:
T
- the generic type parameter.
public class GenericType<T> extends Object
Represents a generic message entity typeT
. 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-classingGenericType
. Alternatively, an object representing a concrete parameterized type can be created using aGenericType(java.lang.reflect.Type)
and manually specifying theactual (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
- Author:
- Marek Potociar, Paul Sandoz, Martin Matula
-
-
Constructor Summary
Constructors Modifier Constructor and Description protected
GenericType()
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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description boolean
equals(Object obj)
Class<?>
getRawType()
Returns the object representing the class or interface that declared the type represented by this generic type instance.Type
getType()
Retrieve the type represented by the generic type instance.int
hashCode()
String
toString()
-
-
-
Constructor Detail
-
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
public GenericType(Type 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 Detail
-
getType
public final Type getType()
Retrieve the type represented by the generic type instance.- Returns:
- the actual type represented by this generic type instance.
-
getRawType
public final Class<?> 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.
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
21/08/2025 18:31:20 Cette version de la page est en cache (à la date du 21/08/2025 18:31:20) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 18/08/2025
Source du document imprimé : https://www.gaudry.be/java-api-javaee-rf-javax/ws/rs/core/GenericType.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.