Java compatibility: how to declare a compilation array constant in Kotlin?

I got this Java annotation ad and want to use it in Kotlin

class CurlCommand {
    Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
    var groups: Array<String>? = null
}

TYPE_MISMATCH compiler reports Required: kotlin.Array <kotlin.String> Found: kotlin.String

Ive tried

Parameter(names = Array<String>(1, {i-> "-groups"}), description = "Comma-separated list of group names to be run")
var groups: Array<String>? = null

and got "Error: (20, 23) Kotlin: annotation parameter must be a compile-time constant"

How can I satisfy the Kotlin compiler?

Java just accepts

@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;
+4
source share
2 answers

You declare a constant in Kotlin like this:

const val LG_PACKAGE = "com.myapp"

kotlin , String . , , , :

const val LG_PACKAGE = "com.myapp"

@EnableJpaRepositories(basePackages = arrayOf(LG_PACKAGE))
@EntityScan(basePackages = arrayOf(LG_PACKAGE))
open class LgApp {
+4

,

array("-groups")

Kotlin

@Parameter(names = "-groups", description = "Comma-separated list of group names to be run")
public String groups;

.

+1

All Articles