【发布时间】:2017-05-25 14:05:51
【问题描述】:
我有一个类,我要么知道创建的特定价值,要么需要生成它,这有点贵。我可以仅在实际需要时生成值吗?
val expensiveProperty: A
constructor(expensiveProperty: A) {
this.expensiveProperty = expensiveProperty
}
constructor(value: B) {
// this doesn't work
this.expensiveProperty = lazy { calculateExpensiveProperty(value) }
}
【问题讨论】:
-
this 可能会有所帮助
标签: kotlin