Skip to content

Commit 98d526a

Browse files
committed
DocumentId.java: add comments for it too
1 parent 95df314 commit 98d526a

File tree

1 file changed

+15
-0
lines changed
  • firebase-firestore/src/main/java/com/google/firebase/firestore

1 file changed

+15
-0
lines changed

firebase-firestore/src/main/java/com/google/firebase/firestore/DocumentId.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@
4343
* WriteBatch#set(DocumentReference, Object)}), the property annotated by {@code @DocumentId} is
4444
* ignored, which allows writing the POJO back to any document, even if it's not the origin of the
4545
* POJO.
46+
*
47+
* <h3>Kotlin Note</h3>
48+
* When applying this annotation to a property of a Kotlin class, the {@code @set} use-site target
49+
* should always be used. There is no need to use the {@code @get} use-site target as this
50+
* annotation is <em>only</em> considered when <em>reading</em> instances from Firestore, and is
51+
* ignored when <em>writing</em> instances into Firestore.
52+
* <p>
53+
* Here is an example of a class that can both be written into and read from Firestore whose
54+
* {@code foo} property will be populated with the Document ID when being read and will be ignored
55+
* when being written into Firestore:
56+
* <pre>
57+
* data class Pojo(@set:DocumentId var foo: String? = null) {
58+
* constructor() : this(null) // Used by Firestore to create new instances
59+
* }
60+
* </pre>
4661
*/
4762
@Retention(RetentionPolicy.RUNTIME)
4863
@Target({ElementType.FIELD, ElementType.METHOD})

0 commit comments

Comments
 (0)