# Class Type (6.118.0)

6.118.0 (latest) 6.116.0 6.111.1 6.108.0 6.107.0 6.103.0 6.102.1 6.101.1 6.100.0 6.99.0 6.98.1 6.97.1 6.96.1 6.95.1 6.94.0 6.93.0 6.89.0 6.88.0 6.87.0 6.86.0 6.85.0 6.83.0 6.82.0 6.80.1 6.79.0 6.77.0 6.74.1 6.72.0 6.71.0 6.69.0 6.68.0 6.66.0 6.65.1 6.62.0 6.60.0 6.58.0 6.57.0 6.56.0 6.55.0 6.54.0 6.53.0 6.52.1 6.51.0 6.50.1 6.49.0 6.25.1 6.24.0 6.23.4 6.22.0 6.21.2 6.20.0 6.19.1 6.18.0 6.17.4 6.14.1

    public final class Type implements Serializable

Describes a type in the Cloud Spanner type system. Types can either be primitive (for example,
`INT64` and `STRING`) or composite (for example, `ARRAY<INT64>` or `
STRUCT<INT64,STRING>`).

`Type` instances are immutable.

## Inheritance

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

## Implements

[Serializable](https://docs.oracle.com/javase/8/docs/api/java/io/Serializable.html)

## 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

### array(Type elementType)

    public static Type array(Type elementType)

Returns a descriptor for an array of `elementType`.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `elementType` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### bool()

    public static Type bool()

Returns the descriptor for the `BOOL type`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### bytes()

    public static Type bytes()

Returns the descriptor for the `BYTES` type: a variable-length byte string.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### date()

    public static Type date()

Returns the descriptor for the `DATE` type: a timezone independent date in the range
\[0001-01-01, 9999-12-31).

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### float32()

    public static Type float32()

Returns the descriptor for the `FLOAT32` type: a floating point type with the same value
domain as a Java `float`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### float64()

    public static Type float64()

Returns the descriptor for the `FLOAT64` type: a floating point type with the same value
domain as a Java `double`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### int64()

    public static Type int64()

Returns the descriptor for the `INT64` type: an integral type with the same value domain
as a Java `long`.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### interval()

    public static Type interval()

Returns the descriptor for the `INTERVAL` type: an interval which represents a time
duration as a tuple of 3 values (months, days, nanoseconds). \[Interval(months:-120000, days:
-3660000, nanoseconds: -316224000000000000000), Interval(months:120000, days: 3660000,
nanoseconds: 316224000000000000000)\].

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### json()

    public static Type json()

Returns the descriptor for the `JSON` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### numeric()

    public static Type numeric()

Returns the descriptor for the `NUMERIC` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### pgJsonb()

    public static Type pgJsonb()

Returns the descriptor for the `JSONB` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### pgNumeric()

    public static Type pgNumeric()

Returns the descriptor for the `NUMERIC` type with the `PG_NUMERIC` type
annotation.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### pgOid()

    public static Type pgOid()

Returns the descriptor for the `PG_OID` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### proto(String protoTypeFqn)

    public static Type proto(String protoTypeFqn)

To get the descriptor for the `PROTO` type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `protoTypeFqn` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` Proto fully qualified name (ex: "examples.spanner.music.SingerInfo"). |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### protoEnum(String protoTypeFqn)

    public static Type protoEnum(String protoTypeFqn)

To get the descriptor for the `ENUM` type.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `protoTypeFqn` | `https://docs.oracle.com/javase/8/docs/api/java/lang/String.html` Proto ENUM fully qualified name (ex: "examples.spanner.music.Genre") |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### string()

    public static Type string()

Returns the descriptor for the `STRING` type: a variable-length Unicode character string.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### struct(Type.StructField\[\] fields)

    public static Type struct(Type.StructField[] fields)

Returns a descriptor for a `STRUCT` type: an ordered collection of named and typed
fields.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type.StructField[]` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### struct(Iterable\<Type.StructField\> fields)

    public static Type struct(Iterable<Type.StructField> fields)

Returns a descriptor for a `STRUCT` type: an ordered collection of named and typed
fields.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `fields` | `https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type.StructField>` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### timestamp()

    public static Type timestamp()

Returns the descriptor for the `TIMESTAMP` type: a nano precision timestamp in the range
\[0000-01-01 00:00:00, 9999-12-31 23:59:59.999999999 UTC\].

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### uuid()

    public static Type uuid()

Returns the descriptor for the `UUID` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

## Methods

### equals(Object o)

    public boolean equals(Object o)

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

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

**Overrides** [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-)

### getArrayElementType()

    public Type getArrayElementType()

Returns the type descriptor for elements of this `ARRAY` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type` |   |

### getCode()

    public Type.Code getCode()

Returns the type code corresponding to this type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type.Code` |   |

### getFieldIndex(String fieldName)

    public int getFieldIndex(String fieldName)

Returns the index of the field named `fieldName` in this `STRUCT` type.

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

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

### getProtoTypeFqn()

    public String getProtoTypeFqn()

Returns the full package name for elements of this `Proto or @code Enum` type.

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

### getSpannerTypeName(Dialect dialect)

    public String getSpannerTypeName(Dialect dialect)

Returns the type name as used by the database in the given dialect.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `dialect` | `https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Dialect` |

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

### getStructFields()

    public List<Type.StructField> getStructFields()

Returns the fields of this `STRUCT` type.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.oracle.com/javase/8/docs/api/java/util/List.html<https://docs.cloud.google.com/java/docs/reference/google-cloud-spanner/latest/com.google.cloud.spanner.Type.StructField>` | an immutable list of the fields |

### hashCode()

    public int hashCode()

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

**Overrides** [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--)

### toString()

    public String toString()

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

**Overrides** [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--)