我只有一个带有静态方法的实用程序类
public final class ABC {
/**
* private constructor to prevent from object creation
*/
private ABC() {
}
private static Map<String, String> buildInfo(@NonNull final X x) {
final DataClass dataClass = x.getData();
/**
Some manipulation
**/
return info;
}
}
X类的数据类带有
class X {
DataClass dataClass;
...
};
class DataClass {
...
Optional<String> abc;
...
}
这段代码给出“ FindBugs已报告警告”。 DataClass的SE_BAD_FIELD: Non-transient non-Serialization instance field in serializable class
。
This Serializable class defines a non-primitive instance field which is neither transient, Serializable, or java.lang.Object, and does not appear to implement the Externalizable interface or the readObject() and writeObject() methods. Objects of this class will not be deserialized correctly if a non-Serializable object is stored in this field.
为什么它在实用程序方法中给此错误,而我不想使事情可序列化?