Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

GuardedBy

@Target([AnnotationTarget.FIELD, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER]) class GuardedBy
androidx.annotation.GuardedBy

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 constructors
<init>(value: String)

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

Properties
String

Public constructors

<init>

GuardedBy(value: String)

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; }

Properties

value

val value: String