ParameterizedType
Stay organized with collections
Save and categorize content based on your preferences.
ParameterizedType represents a parameterized type such as
Collection<String>.
A parameterized type is created the first time it is needed by a
reflective method, as specified in this package. When a
parameterized type p is created, the generic type declaration that
p instantiates is resolved, and all type arguments of p are created
recursively. See TypeVariable
for details on the creation process for type
variables. Repeated creation of a parameterized type has no effect.
Instances of classes that implement this interface must implement
an equals() method that equates any two instances that share the
same generic type declaration and have equal type parameters.
Public Method Summary
abstract
Type[]
|
getActualTypeArguments()
Returns an array of Type objects representing the actual type
arguments to this type.
|
abstract
Type
|
getOwnerType()
Returns a Type object representing the type that this type
is a member of.
|
abstract
Type
|
getRawType()
Returns the Type object representing the class or interface
that declared this type.
|
Public Methods
public
abstract
Type[]
getActualTypeArguments
()
Returns an array of Type
objects representing the actual type
arguments to this type.
Note that in some cases, the returned array be empty. This can occur
if this type represents a non-parameterized type nested within
a parameterized type.
Returns
- an array of
Type
objects representing the actual type
arguments to this type
public
abstract
Type
getOwnerType
()
Returns a Type
object representing the type that this type
is a member of. For example, if this type is O<T>.I<S>
,
return a representation of O<T>
.
If this type is a top-level type, null
is returned.
Returns
- a
Type
object representing the type that
this type is a member of. If this type is a top-level type,
null
is returned
public
abstract
Type
getRawType
()
Returns the Type
object representing the class or interface
that declared this type.
Returns
- the
Type
object representing the class or interface
that declared this type
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-07-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-07-10 UTC."],[[["\u003cp\u003e\u003ccode\u003eParameterizedType\u003c/code\u003e represents parameterized types in Java reflection, like \u003ccode\u003eCollection<String>\u003c/code\u003e, providing information about its structure.\u003c/p\u003e\n"],["\u003cp\u003eIt gives access to the actual type arguments, the owner type if it's a nested type, and the raw type (the declaring class/interface).\u003c/p\u003e\n"],["\u003cp\u003eThe methods \u003ccode\u003egetActualTypeArguments()\u003c/code\u003e, \u003ccode\u003egetOwnerType()\u003c/code\u003e, and \u003ccode\u003egetRawType()\u003c/code\u003e can throw exceptions if the type information is invalid or incomplete.\u003c/p\u003e\n"],["\u003cp\u003eCreation of a \u003ccode\u003eParameterizedType\u003c/code\u003e is triggered on demand by reflection and is idempotent, ensuring consistency and avoiding redundant computations.\u003c/p\u003e\n"]]],["`ParameterizedType` represents types like `Collection\u003cString\u003e`. It's created reflectively when needed, resolving its generic type declaration and type arguments. Instances must equate if they share the same declaration and parameters. Key actions involve using the methods `getActualTypeArguments()` to retrieve an array of `Type` objects, `getOwnerType()` to get the type it's a member of, or `null` if top-level, and `getRawType()` to return the class or interface declaring it.\n"],null,["public interface **ParameterizedType** implements [Type](../../../../reference/java/lang/reflect/Type.html) \nParameterizedType represents a parameterized type such as\nCollection\\\u003cString\\\u003e.\n\nA parameterized type is created the first time it is needed by a\nreflective method, as specified in this package. When a\nparameterized type p is created, the generic type declaration that\np instantiates is resolved, and all type arguments of p are created\nrecursively. See [TypeVariable](../../../../reference/java/lang/reflect/TypeVariable.html) for details on the creation process for type\nvariables. Repeated creation of a parameterized type has no effect.\n\nInstances of classes that implement this interface must implement\nan equals() method that equates any two instances that share the\nsame generic type declaration and have equal type parameters. \n\nPublic Method Summary\n\n|------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract [Type\\[\\]](../../../../reference/java/lang/reflect/Type.html) | [getActualTypeArguments](../../../../reference/java/lang/reflect/ParameterizedType.html#getActualTypeArguments())() Returns an array of `Type` objects representing the actual type arguments to this type. |\n| abstract [Type](../../../../reference/java/lang/reflect/Type.html) | [getOwnerType](../../../../reference/java/lang/reflect/ParameterizedType.html#getOwnerType())() Returns a `Type` object representing the type that this type is a member of. |\n| abstract [Type](../../../../reference/java/lang/reflect/Type.html) | [getRawType](../../../../reference/java/lang/reflect/ParameterizedType.html#getRawType())() Returns the `Type` object representing the class or interface that declared this type. |\n\nPublic Methods \n\npublic abstract [Type\\[\\]](../../../../reference/java/lang/reflect/Type.html)\n**getActualTypeArguments**\n() \nReturns an array of `Type` objects representing the actual type\narguments to this type.\n\nNote that in some cases, the returned array be empty. This can occur\nif this type represents a non-parameterized type nested within\na parameterized type. \n\nReturns\n\n- an array of `Type` objects representing the actual type arguments to this type \n\nThrows\n\n| [TypeNotPresentException](../../../../reference/java/lang/TypeNotPresentException.html) | if any of the actual type arguments refers to a non-existent type declaration |\n| [MalformedParameterizedTypeException](../../../../reference/java/lang/reflect/MalformedParameterizedTypeException.html) | if any of the actual type parameters refer to a parameterized type that cannot be instantiated for any reason |\n|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------|\n\npublic abstract [Type](../../../../reference/java/lang/reflect/Type.html)\n**getOwnerType**\n() \nReturns a `Type` object representing the type that this type\nis a member of. For example, if this type is `O\u003cT\u003e.I\u003cS\u003e`,\nreturn a representation of `O\u003cT\u003e`.\n\nIf this type is a top-level type, `null` is returned. \n\nReturns\n\n- a `Type` object representing the type that this type is a member of. If this type is a top-level type, `null` is returned \n\nThrows\n\n| [TypeNotPresentException](../../../../reference/java/lang/TypeNotPresentException.html) | if the owner type refers to a non-existent type declaration |\n| [MalformedParameterizedTypeException](../../../../reference/java/lang/reflect/MalformedParameterizedTypeException.html) | if the owner type refers to a parameterized type that cannot be instantiated for any reason |\n|-------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------|\n\npublic abstract [Type](../../../../reference/java/lang/reflect/Type.html)\n**getRawType**\n() \nReturns the `Type` object representing the class or interface\nthat declared this type. \n\nReturns\n\n- the `Type` object representing the class or interface that declared this type"]]