kotlin - Android Kotlin Room Entity data class should be var, val or don't care?
问题描述
I am trying to be conventional, that is why I am refactoring some Kotlin codes in an Android project last few days. I looked at many Room entity data class example, but still not get the best practice of use of val/var in the context of Room. I suspect that the suitable way should be val since it is at the persistence layer and DTO (Data Transfer Objects) should be created about these entities which can be modified. Can someone please assure or deny this hypothesis!?
解决方案
有点晚了,但也许有些人正在寻找答案。简而言之:没关系。当指定参数 val 仅用于创建 getter 时,var 为属性创建 getter 和 setter。
推荐阅读
- javascript - 如何在不同的文本区域显示用户的输入?
- angular - 从拖放组件中获取json数据
- sql - 我如何总结每个产品的每个月的数据?
- regex - 如何为正则表达式创建业务逻辑并将数据保存到 csv 文件
- python - 带有聚合的 Pandas groupby
- node.js - 使用 Google Trends API 将数据插入 PostgreSQL
- javascript - posenet 是机器学习模型还是深度学习模型
- xslt - 使用 key() 和 count() 计算仅包含客人且是女性还是男性的剧集数?
- flutter - 在颤动中减少应用栏按钮中的填充
- oracle - 使用 JPA hibernate 创建表后无法在 Oracle 数据库中获取表