【问题标题】:How to ignore kotlin delegated property using Room ```@Ignore``` annotation如何使用 Room ``@Ignore``` 注释忽略 kotlin 委托属性
【发布时间】:2020-05-29 07:17:09
【问题描述】:

我想给我的Composition类添加一个委托属性,如下

@Entity
data class Composition(
        val author: String="",
        val background: String?,
        val description: String="",
        val downloadURL: String="",
        val duration: String="",
        val headPortrait: String?,
        @PrimaryKey val id: String,
        val isLike: Boolean,
        val likeAmount: String="",
        val playingAmount: Int=0,
        val replyAmount: String?,
        val showStyle: String?,
        val title: String?,
        val userId: String?,
        val commentAmount: String?,
        val cover: String=""
){

    val  showDuration by lazy{
        val minutes = duration.toInt() /60
        val seconds =duration.toInt()%60
        "$minutes:$seconds"
    }
}

但是会出现编译错误,因为委托属性无法保存在数据库中。所以我想 添加一个 Ignore 对此字段的注释。可惜Androidstuio会报错"This annotation is not applicable to target 'member property with delegate"。谁有这个问题的想法?

【问题讨论】:

  • @delegate:Ignore

标签: kotlin android-room


【解决方案1】:

正如用户IR42 在他的评论中指出的那样,您可以使用@delegate:Ignore

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2017-12-22
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多