PhantomThief
PhantomThief

Reputation: 307

How to refer java variable length arguments in kotlin?

I can refer String in kotlin as String::class.java but how to refer String...?

I need to use it to test a private method

private void someMethod(int a, int b, String... c) {
   . . .
}
val method: Method = SomeActivity::class.java.getDeclaredMethod(
            "someMethod",
            Int::class.java,
            Int::class.java,
            {{need help here}}
        )
method.isAccessible = true
method.invoke(activity, 0, 0, "")

Upvotes: 0

Views: 123

Answers (1)

PhantomThief
PhantomThief

Reputation: 307

I can refer to it easily using Array<String>::class.java

val method: Method = SomeActivity::class.java.getDeclaredMethod(
            "someMethod",
            Int::class.java,
            Int::class.java,
            Array<String>::class.java
        )
method.isAccessible = true
method.invoke(activity, 0, 0, arrayOf(""))

Upvotes: 1

Related Questions