Skip to content

Commit 8f13f2b

Browse files
committed
Alejandro review
1 parent 65fe9e7 commit 8f13f2b

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

docs/topics/jvm/jvm-records.md

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,45 +65,24 @@ JVM records require the `16` target version or higher of the generated JVM bytec
6565

6666
To specify it explicitly, use the `jvmTarget` compiler option in [Gradle](gradle-compiler-options.md#attributes-specific-to-jvm) or [Maven](maven.md#attributes-specific-to-jvm).
6767

68-
## Annotate records in Kotlin
69-
70-
To make an [annotation](annotations.md) available on both Kotlin properties **and** Java record components, add the
71-
following meta-annotations to your annotation declaration:
72-
73-
* For Kotlin: [`@Target`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.annotation/-target/index.html)
74-
* For Java record components: [`@java.lang.annotation.Target`](https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html)
75-
76-
For example:
77-
78-
```kotlin
79-
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY)
80-
@java.lang.annotation.Target(ElementType.CLASS, ElementType.RECORD_COMPONENT)
81-
annotation class exampleClass
82-
```
83-
84-
The `exampleClass` annotation can now be applied to Kotlin classes and properties, as well as Java classes and record
85-
components.
86-
87-
### Propagate annotations of a record component
68+
## Annotate record components in Kotlin
8869

8970
<primary-label ref="experimental-general"/>
9071

91-
<!-- Add warning about `@all` needing opt-in -->
92-
93-
In Java, annotations on a record component are automatically propagated to the backing field, getter, and constructor parameter.
72+
In Java, [annotations](annotations.md) on a record component are automatically propagated to the backing field, getter, setter, and constructor parameter.
9473
You can replicate this behavior in Kotlin by using the [`all`](annotations.md) use-site target.
9574

9675
> To use the `all` use-site target, you must opt in. Either use the `-Xannotation-target-all` compiler option or add
9776
> the following to your `build.gradle.kts` file:
98-
>
77+
>
9978
> ```kotlin
10079
> kotlin {
10180
> compilerOptions {
10281
> freeCompilerArgs.add("-Xannotation-target-all")
10382
> }
10483
> }
10584
> ```
106-
>
85+
>
10786
{style="warning"}
10887
10988
For example:
@@ -115,9 +94,27 @@ data class Person(val name: String, @all:Positive val age: Int)
11594
11695
When you use `@JvmRecord` with `@all:`, Kotlin:
11796

118-
* Propagates the annotation to the property, backing field, constructor parameter, and getter.
97+
* Propagates the annotation to the property, backing field, constructor parameter, getter and setter.
11998
* Applies the annotation to the record component as well, if the annotation supports Java's `RECORD_COMPONENT`.
12099

100+
## Make annotations work with record components
101+
102+
To make an [annotation](annotations.md) available on both Kotlin properties **and** Java record components, add the
103+
following meta-annotations to your annotation declaration:
104+
105+
* For Kotlin: [`@Target`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.annotation/-target/index.html)
106+
* For Java record components: [`@java.lang.annotation.Target`](https://docs.oracle.com/javase/8/docs/api/java/lang/annotation/Target.html)
107+
108+
For example:
109+
110+
```kotlin
111+
@Target(AnnotationTarget.CLASS, AnnotationTarget.PROPERTY)
112+
@java.lang.annotation.Target(ElementType.CLASS, ElementType.RECORD_COMPONENT)
113+
annotation class exampleClass
114+
```
115+
116+
You can now apply `@ExampleClass` to Kotlin classes and properties, as well as Java classes and record components.
117+
121118
## Further discussion
122119

123120
See this [language proposal for JVM records](https://github.com/Kotlin/KEEP/blob/master/proposals/jvm-records.md) for further technical details and discussion.

0 commit comments

Comments
 (0)