GuardedBy

@Target(value = [ElementType.FIELD, ElementType.METHOD])  @Retention(value = RetentionPolicy.CLASS) 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 methods

abstract @NonNull String

Public methods

value

@NonNull
public abstract String value()