# StringDef

Artifact: [androidx.annotation:annotation](https://developer.android.com/jetpack/androidx/releases/annotation) [View Source](https://cs.android.com/search?q=file:androidx/annotation/StringDef.kt+class:androidx.annotation.StringDef) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.0.0)

*** ** * ** ***

Common/AllAndroid/JVM
- Cmn

  ```
  @Retention(value = AnnotationRetention.SOURCE)
  @Target(allowedTargets = [AnnotationTarget.ANNOTATION_CLASS])
  annotation StringDef
  ```

*** ** * ** ***

Denotes that the annotated String element, represents a logical type and that its value should be one of the explicitly named constants.

Example:

```kotlin
@Retention(SOURCE)
@StringDef({
    POWER_SERVICE,
    WINDOW_SERVICE,
    LAYOUT_INFLATER_SERVICE
})
public @interface ServiceName {}
public static final String POWER_SERVICE = "power";
public static final String WINDOW_SERVICE = "window";
public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
...
public abstract Object getSystemService(@ServiceName String name);
```

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/StringDef#StringDef(kotlin.Array,kotlin.Boolean)(vararg value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html, open: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/StringDef#open()` Whether any other values are allowed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html>` | `https://developer.android.com/reference/kotlin/androidx/annotation/StringDef#value()` Defines the allowed constants for this element | Cmn |

## Public constructors

### StringDef

Cmn Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/annotation#1.10.0)

```
StringDef(vararg value: String = [], open: Boolean = false)
```

## Public properties

### open

Cmn

```
val open: Boolean
```

Whether any other values are allowed. Normally this is not the case, but this allows you to specify a set of expected constants, which helps code completion in the IDE and documentation generation and so on, but without flagging compilation warnings if other values are specified.

### value

Cmn

```
val value: Array<String>
```

Defines the allowed constants for this element