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

*** ** * ** ***


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

<br />

*** ** * ** ***

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

Example:

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

@GuardedBy("objectLock")
volatile Object object;

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

## 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/annotation/GuardedBy#getValue()()` |

## Public methods

### getValue

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