# GuardedBy

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

*** ** * ** ***

Common/AllAndroid/JVM
- Cmn

  ```
  @Target(allowedTargets = [AnnotationTarget.FIELD, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER])
  @Retention(value = AnnotationRetention.BINARY)
  annotation GuardedBy
  ```

*** ** * ** ***

Denotes that the annotated method or field can only be accessed when holding the referenced lock.

Example:

```kotlin
final Object objectLock = new Object();

@GuardedBy("objectLock")
volatile Object object;

Object getObject() {
    synchronized (objectLock) {
        if (object == null) {
            object = new Object();
        }
    }
    return object;
}
```

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy#GuardedBy(kotlin.String)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/annotation/GuardedBy#value()` | Cmn |

## Public constructors

### GuardedBy

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

```
GuardedBy(value: String)
```

## Public properties

### value

Cmn

```
val value: String
```