PropertyModel不能与Kotlin的私人领域一起使用get()

如果一个kotlin的模型有一个字段:

class MyModel { private val theValue: Double get() { return 1.0 } } 

并在检票页面:

 new PropertyModel(model , "theValue") 

它会失败:

 WicketRuntimeException: Property could not be resolved for class: class MyModel expression: theValue 

解决方案:删除私人修改器:

 class MyModel { val theValue: Double get() { return 1.0 } } 

有没有办法解决这个问题(保持私人修改)?

(wicket 7.9.0,Kotlin 1.2)

由于需要读取和写入模型,因此您的模型需要具有支持字段的属性。

 class MyModel { private val theValue: Double get() { return 1.0 } } 

没有后台字段,即使您删除了private修改器。

试试像这样:

 class MyModel { var theValue = 1.0 } 

或者如果你需要equals()hashCode()等开箱即用:

 data class MyModel(var theValue: Double = 1.0) 

注:Wicket是一个Java框架。 在文档中明确指出,你需要一个Java bean作为模型,它在第二个代码片段中。

Interesting Posts