要为数据绑定适配器使用多个参数,Java语法是
@BindingAdapter(value={"arg1", "arg2"}, requireAll = false)
However this does not compile in Kotlin:
Error:(13, 37) Unexpected tokens (use ';' to separate expressions on the same line)
Kotlin中多个参数的正确语法是什么?
要为数据绑定适配器使用多个参数,Java语法是
@BindingAdapter(value={"arg1", "arg2"}, requireAll = false)
However this does not compile in Kotlin:
Error:(13, 37) Unexpected tokens (use ';' to separate expressions on the same line)
Kotlin中多个参数的正确语法是什么?
应该是:
@BindingAdapter(value=*arrayOf("arg1", "arg2"), requireAll = false)
Please refer to the official annotations docs for Java Annotations in Kotlin
引用:
For other arguments that have an array type, you need to use arrayOf explicitly:
// Java
public @interface AnnWithArrayMethod {
String[] names();
}
// Kotlin
@AnnWithArrayMethod(names = arrayOf("abc", "foo", "bar")) class C
EDIT: Credit to @Francesc