# Metadata.Key

Artifact: [androidx.camera:camera-common](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/common/Metadata.kt+class:androidx.camera.common.Metadata.Key) Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

*** ** * ** ***


```
public final class Metadata.Key<T extends Object>
```

<br />

*** ** * ** ***

A type-safe key used to identify and retrieve values from a `https://developer.android.com/reference/androidx/camera/common/Metadata` container.

Keys are unique by their `https://developer.android.com/reference/androidx/camera/common/Metadata.Key#name()`. Only one `https://developer.android.com/reference/androidx/camera/common/Metadata.Key` instance can exist for a given name. Attempting to create a key with an existing name but a different `https://developer.android.com/reference/androidx/camera/common/Metadata.Key#type()` will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.
> !IMPORTANT Creating new `https://developer.android.com/reference/androidx/camera/common/Metadata.Key` instances is restricted to the AndroidX Camera library group. External clients can use predefined keys but cannot define their own.

### Examples (Internal Library Usage Only)

Creating keys in Kotlin:

```
// For primitive/standard types:
val widthKey = Metadata.Key<Int>("androidx.camera.width")
val nameKey = Metadata.Key<String>("androidx.camera.name")

// For custom classes:
class MyConfig(val value: String)
val configKey = Metadata.Key<MyConfig>("androidx.camera.config")
```

| Parameters |
|---|---|
| `<T extends https://developer.android.com/reference/java/lang/Object.html>` | The type of the value associated with this key (must be non-nullable). |

## Summary

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/common/Metadata.Key#getName()()` The unique string name identifying this key. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` | `https://developer.android.com/reference/androidx/camera/common/Metadata.Key#getType()()` The `https://developer.android.com/reference/java/lang/Class.html` representing the type of the value associated with this key. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/camera/common/Metadata.Key#toString()()` |

## Public methods

### getName

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull String getName()
```

The unique string name identifying this key.

### getType

Added in [1.7.0-rc02](https://developer.android.com/jetpack/androidx/releases/camera#1.7.0-rc02)

```
public final @NonNull Class<@NonNull T> getType()
```

The `https://developer.android.com/reference/java/lang/Class.html` representing the type of the value associated with this key.

### toString

```
public @NonNull String toString()
```