我尝试使用kotlin扩展Java类的数字类型属性,如下所示:
// Java class
public class Person {
private Number old;
public Number getOld() {
return old;
}
public void setOld(Number a) {
this.old = a;
}
}
和我的Kotlin代码:
// Kotlin code
var Person.age: Number
inline get() = old
inline set(value) { old = value }
fun main(args: Array<String>) {
val person = Person()
person.age = 20
}
运行代码,它会出错:
java.lang.VerifyError: Bad local variable type
Exception Details:
Location:
net/wenris/fx10/EntryKt.main([Ljava/lang/String;)V @20: aload_3
Reason:
Type integer (current frame, locals[3]) is not assignable to reference type
Current Frame:
...
这里有什么问题?
顺便说一句,如果我删除了set()方法的内联关键字,那就没问题了。