【发布时间】:2018-07-18 18:18:43
【问题描述】:
我有以下情况,一个名为save的扩展函数来自Marker
1.代码
fun Marker.save(ctx: Context) {
//database is an extension property from Context
ctx.database.use {
insert("markers",
"id" to this@save.id,
"latitude" to this@save.position.latitude,
"longitude" to this@save.position.longitude,
"name" to this@save.title)
}
}
代码对我来说很好。
2。问题
要在save 方法中使用Marker 的实例,我需要使用this@save,但这个名称并不具有暗示性,乍一看,它不像Marker。
3.问题
是否可以应用别名来代替this@save?
非常感谢!
【问题讨论】:
标签: android kotlin alias extension-function