Java PMD对非临时类成员的警告 [英] Java PMD warning on non-transient class member

查看:1336
本文介绍了Java PMD对非临时类成员的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在线:

private boolean someFlag;

我收到以下PMD警告:

I get the following PMD warning:

找到非瞬态,非静态成员。

Found non-transient, non-static member. Please mark as transient or provide accessors.

有人可以解释为什么会有这个警告,这是什么意思? (我明白如何解决它,我不明白为什么它在那里...)

Can someone please explain why this warning is there and what it means? (I understand how to fix it, I don't understand why it's there...)

我得到这个在许多其他成员声明以及...

I'm getting this on many other member declarations as well...

EDIT:我的课程不可序列化...

My class is definitely not a bean, and not serializable...

推荐答案

我假设你的类是一个bean,通过定义实现 Serializable 。临时变量将从序列化过程中排除。如果你序列化然后反序列化bean的值将实际上具有默认值。

I assume your class is a bean that by definition implements Serializable. A transient variable will be excluded from the serialization process. If you serialize and then deserialize the bean the value will be actually have the default value.

PMD假设你在这里处理一个可序列化的bean。对于bean,它应该有所有成员变量的getters / setters。因为你省略了这些,你的意思是你的成员变量不是bean的一部分....所以不需要序列化。如果是这种情况,你应该从序列化中排除它。你通过将变量标记为transient来做。

PMD assumes you are dealing with a serializable bean here. For a bean it is expected to have getters/setters for all member variables. As you have omitted these, you imply that your member variable is not part of the bean ....and so does not need to be serialized. If that is the case you should exclude it from the serialization. Which you do by marking the variable as "transient".

这篇关于Java PMD对非临时类成员的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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