java - 是否可以使用反射获取类中的 transient 场

标签 java reflection transient

类中的transient字段能否通过反射获取? (使用 getDeclaredField(..))

最佳答案

,这是一个普通字段。您可以通过以下方式检查它是否是 transient 的:

Modifier.isTransient(field.getModifiers());

transient: A keyword in the Java programming language that indicates that a field is not part of the serialized form of an object. When an object is serialized, the values of its transient fields are not included in the serial representation, while the values of its non-transient fields are included.

因此没有合乎逻辑的理由不能通过反射访问它。被忽略的是字段的值(有时),而不是字段本身。

(顺便说一句,是什么阻碍了您尝试调用 getDeclaredField("yourTransientField")?)

关于java - 是否可以使用反射获取类中的 transient 场,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2256734/

相关文章:

java - 将字节数组转换为固定长度的字母数字字符串

c# - .NET 反射 : how to get properties defined on partial class

c# - 具有不同返回类型的重载函数缺少 MethodInfo

validation - Grails:自定义验证器中无法访问 transient 变量?

java - 如何在 HyperJaxb3 中将生成的属性注释为 Transient

java - 应该在 equals/hashCode/toString 中使用 @Transient 属性吗?

java - 登录系统 JSF - 识别出 SQLException?

java - Java 中计算大 n 和 k 值模 10^9 + 7 的二项式系数的乘法公式输出错误值

java - 使用数据库身份验证设置 CAS Jasig 服务器

java - 如何在Java反射中获取字段值