Android Room:@Ignore vs Transient [英] Android Room: @Ignore vs Transient

查看:121
本文介绍了Android Room:@Ignore vs Transient的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两者在 Room 数据库实体的上下文中是否可以互换,或者,如果不能,它们之间有什么区别?

Are those two interchangable in context of Room database entity, or, if not, what are the differences between them?

推荐答案

@Ignore 是 Room 特定的注解,表示 Room 应该忽略该字段或方法.

@Ignore is a Room-specific annotation, saying that Room should ignore that field or method.

transient 是一个 Java 结构,表示这个字段在标准 Java 序列化中不应该被序列化.默认情况下,可能将此处理方式与 @Ignore 类似.大多数情况下,这适用于您从某个碰巧使用 transient 的类继承而您不控制该类(例如,它来自库)的情况.

transient is a Java construct, indicating that this field should not be serialized in standard Java serialization. Room happens to treat this similarly to @Ignore by default. Mostly, that is there for cases where you are inheriting from some class that happens to use transient and you do not control that class (e.g., it is from a library).

对于您自己的代码,如果您不使用 Java 序列化,我建议对字段使用 @Ignore.transient 不是方法的可用关键字,因此要告诉 Room 忽略某些构造函数,您别无选择,只能使用 @Ignore.

For your own code, if you are not using Java serialization, I recommend sticking with @Ignore for the fields. transient is not an available keyword for a method, so to tell Room to ignore certain constructors, you have no choice but to use @Ignore.

这篇关于Android Room:@Ignore vs Transient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆