Skip to content

Commit 89ec1f6

Browse files
committed
Add example of single param annonymous Java defined annotatios
1 parent 6059284 commit 89ec1f6

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

_posts/2024-12-05-release-notes-3.6.2.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,31 @@ Let's take the following example:
179179
```
180180

181181
Reordering the fields is binary-compatible but it might affect the meaning of `@Annotation(1)`
182-
Starting from Scala 3.6, named arguments are required for Java-defined annotations.
182+
Starting from Scala 3.6, named arguments are required for Java-defined annotations that define multiple parameters. Java defined annotations with a single parameter named `value` can still be used anonymously.
183+
184+
```Java
185+
public @interface CanonicalAnnotation {
186+
String value() default "";
187+
}
188+
public @interface CustomAnnotation {
189+
String param() default "";
190+
}
191+
```
192+
193+
```Scala
194+
class NoExplicitNames(
195+
@CanonicalAnnotation() useDefault: String,
196+
@CanonicalAnnotation(value = "myValue") named: String
197+
@CanonicalAnnotation("myValue") unnamed: String
198+
)
199+
200+
class ExplicitNamesRequired(
201+
@CustomAnnotation() useDefault: String,
202+
@CustomAnnotation(param = "myParam") named: String
203+
@CustomAnnotation("unnamedParam") invalid: String // error
204+
)
205+
```
206+
183207
The compiler can provide you with automatic rewrites introducing now required names, using `-source:3.6-migration, -rewrite` flags. The rewrites are done on a best-effort basis and should be inspected for correctness by the users.
184208

185209
## Experimental SIP-58 - Named Tuples

0 commit comments

Comments
 (0)