# Class Types (2.1.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [2.1.0 (latest)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Types)
- [2.0.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/2.0.3/com.google.api.client.util.Types)
- [1.47.1](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.Types)
- [1.46.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.Types)
- [1.45.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.Types)
- [1.44.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.Types)
- [1.43.2](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.Types)
- [1.42.3](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.Types)
- [1.41.8](https://docs.cloud.google.com/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.Types)

    public class Types

Utilities for working with Java types.

## Inheritance

[Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> Types

## Inherited Members

[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Static Methods

### \<T\>iterableOf(Object value)

    public static Iterable<T> <T>iterableOf(Object value)

Returns an iterable for an input iterable or array value.

If the input value extends [Iterable](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html), it will just return the input value. Otherwise,
it will return an iterable that can handle arrays of primitive and non-primitive component
type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `value` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` iterable (extends [Iterable](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)) or array value |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<T>` | iterable |

### \<T\>newInstance(Class\<T\> clazz)

    public static T <T>newInstance(Class<T> clazz)

Creates a new instance of the given class by invoking its default constructor.

The given class must be public and must have a public default constructor, and must not be
an array or an interface or be abstract. If an enclosing class, it must be static.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `clazz` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<T>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `T` |   |

### getArrayComponentType(Type array)

    public static Type getArrayComponentType(Type array)

Returns the component type of the given array type, assuming [#isArray(Type)](https://docs.cloud.google.com/java/docs/reference/google-http-client/latest/com.google.api.client.util.Types#com_google_api_client_util_Types_isArray_java_lang_reflect_Type_).

Return type will either be class, parameterized type, generic array type, or type variable,
but not a wildcard type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `array` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` |   |

### getBound(WildcardType wildcardType)

    public static Type getBound(WildcardType wildcardType)

Returns the only bound of the given wildcard type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `wildcardType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/WildcardType.html` wildcard type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` | only bound or `Object.class` for none |

### getIterableParameter(Type iterableType)

    public static Type getIterableParameter(Type iterableType)

Returns the type parameter of [Iterable](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html) that is assignable from the given iterable type.

For example, for the type `ArrayList<Integer>` -- or for a class that extends `
ArrayList<Integer>` -- it will return `Integer`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `iterableType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` iterable type (must extend [Iterable](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` | type parameter, which may be any type |

### getMapValueParameter(Type mapType)

    public static Type getMapValueParameter(Type mapType)

Returns the value type parameter of [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html) that is assignable from the given map type.

For example, for the type `Map<String, Integer>` -- or for a class that extends `
Map<String, Integer>` -- it will return `Integer`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `mapType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` map type (must extend [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html)) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` | type parameter, which may be any type |

### getRawArrayComponentType(List\<Type\> context, Type componentType)

    public static Class<?> getRawArrayComponentType(List<Type> context, Type componentType)

Returns the raw array component type to use -- for example for the first parameter of Array#newInstance(Class, int) -- for the given component type.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html>` context list, ordering from least specific to most specific type context, for example container class and then its field |
| `componentType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` array component type or `null` for `Object.class` result |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` | raw array component type |

### getRawClass(ParameterizedType parameterType)

    public static Class<?> getRawClass(ParameterizedType parameterType)

Returns the raw class for the given parameter type as defined in ParameterizedType#getRawType().

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `parameterType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/ParameterizedType.html` parameter type |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` | raw class |

### getSuperParameterizedType(Type type, Class\<?\> superClass)

    public static ParameterizedType getSuperParameterizedType(Type type, Class<?> superClass)

Returns the parameterized type that is or extends the given type that matches the given super
class.

For example, if the input type is `HashMap<String,Integer>` and the input super class
is `Map.class`, it will return the extended parameterized type [Map](https://docs.oracle.com/javase/8/docs/api/java/util/Map.html), but which
retains the actual type information from the original `HashMap`.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` class or parameterized type |
| `superClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` super class |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/ParameterizedType.html` | matching parameterized type or `null` |

### isArray(Type type)

    public static boolean isArray(Type type)

Returns whether the given type is an array.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `type` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### isAssignableToOrFrom(Class\<?\> classToCheck, Class\<?\> anotherClass)

    public static boolean isAssignableToOrFrom(Class<?> classToCheck, Class<?> anotherClass)

Returns whether a class is either assignable to or from another class.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `classToCheck` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` class to check |
| `anotherClass` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` another class |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html` |   |

### resolveTypeVariable(List\<Type\> context, TypeVariable\<?\> typeVariable)

    public static Type resolveTypeVariable(List<Type> context, TypeVariable<?> typeVariable)

Resolves the actual type of the given type variable that comes from a field type based on the
given context list.

In case the type variable can be resolved partially, it will return the partially resolved
type variable.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `context` | `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html>` context list, ordering from least specific to most specific type context, for example container class and then its field |
| `typeVariable` | `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/TypeVariable.html<?>` type variable |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Type.html` | resolved or partially resolved actual type (type variable, class, parameterized type, or generic array type, but not wildcard type) or `null` if unable to resolve at all |

### toArray(Collection\<?\> collection, Class\<?\> componentType)

    public static Object toArray(Collection<?> collection, Class<?> componentType)

Returns a new array of the given component type (possibly a Java primitive) that is a copy of
the content of the given collection.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `collection` | `https://docs.oracle.com/javase/8/docs/api/java/util/Collection.html<?>` collection |
| `componentType` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html<?>` component type (possibly a Java primitive) |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html` | new array |