@Annotation("{0}") should compile

#1

I’m trying to customize JUnit 5 test display name. Code @ParameterizedTest("{0}") works in Java, but Kotlin compiler error is Only named arguments are available for Java annotations.

The magic string "{0}" is mandatory in that case and I can’t find way to escape it correctly.

I found that @ParameterizedTest(name = "{0}") compiles as a workaround, but just wondering must I use that “ugly” :slight_smile: syntax.

#2

Yes, this is a limitation of Java interop. See the documentation:

Since the order of parameters for an annotation written in Java is not defined, you can’t use a regular function call syntax for passing the arguments. Instead, you need to use the named argument syntax.

[…]

Just like in Java, a special case is the value parameter; its value can be specified without an explicit name.

BTW, the error message is confusing here: https://youtrack.jetbrains.com/issue/KT-12656. Feel free to vote/follow this issue for updates.