blob: 99f4643c37434f5799f8126b5e88a1c8aef78936 [file]
<html devsite="true">
<head>
<title>GuardedBy</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<div itemscope="" itemtype="http://developers.google.com/ReferenceObject">
<meta itemprop="name" content="GuardedBy">
<meta itemprop="path" content="androidx.annotation">
<meta itemprop="property" content="getValue()">
<meta itemprop="language" content="JAVA">
</div>
<div id="header-block">
<div>
<h1>GuardedBy</h1>
</div>
<div id="metadata-info-block">
<div id="source-link"><a href="https://cs.android.com/search?q=file:androidx/annotation/GuardedBy.kt+class:androidx.annotation.GuardedBy&amp;ss=androidx/platform/frameworks/support" class="external">View Source</a></div>
</div>
</div>
<div id="refdoc-switcher-placeholder"></div>
<p>
<pre>@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.annotation/-target/index.html">Target</a>(allowedTargets&nbsp;=&nbsp;[AnnotationTarget.FIELD,&nbsp;AnnotationTarget.FUNCTION,&nbsp;AnnotationTarget.PROPERTY_GETTER,&nbsp;AnnotationTarget.PROPERTY_SETTER])<br>@<a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.annotation/-retention/index.html">Retention</a>(value&nbsp;=&nbsp;AnnotationRetention.BINARY)<br>public annotation <a href="/reference/androidx/annotation/GuardedBy.html">GuardedBy</a></pre>
</p>
<hr>
<p>Denotes that the annotated method or field can only be accessed when holding the referenced lock.</p>
<p>Example:</p>
<pre class="prettyprint">final Object objectLock = new Object();<br><br>@GuardedBy(&quot;objectLock&quot;)<br>volatile Object object;<br><br>Object getObject() {<br> synchronized (objectLock) {<br> if (object == null) {<br> object = new Object();<br> }<br> }<br> return object;<br>}</pre>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public constructors</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td>
<div><code><a href="/reference/androidx/annotation/GuardedBy.html#GuardedBy(kotlin.String)">GuardedBy</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;value)</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>final @<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a></code></td>
<td>
<div><code><a href="/reference/androidx/annotation/GuardedBy.html#getValue()">getValue</a>()</code></div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public constructors</h2>
<div class="api-item"><a name="GuardedBy-kotlin.String-"></a><a name="guardedby"></a>
<div class="api-name-block">
<div>
<h3 id="GuardedBy(kotlin.String)">GuardedBy</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;<a href="/reference/androidx/annotation/GuardedBy.html#GuardedBy(kotlin.String)">GuardedBy</a>(@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;value)</pre>
</div>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="getValue--"></a><a name="getvalue"></a>
<div class="api-name-block">
<div>
<h3 id="getValue()">getValue</h3>
</div>
</div>
<pre class="api-signature no-pretty-print">public&nbsp;final&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;<a href="/reference/androidx/annotation/GuardedBy.html#getValue()">getValue</a>()</pre>
</div>
</div>
</body>
</html>