简体   繁体   English

可序列化类中的不可序列化字段(transient 关键字)

[英]Non-serializable field in serializable class (transient keyword)

I have a serializable class that extends Servlet我有一个扩展 Servlet 的可序列化类

public class FileDownload extends HttpServlet{
  @SuppressWarnings("compatibility:6754389671327954013")
  private static final long serialVersionUID = 1L;
  private ResultSet rset;
  ......
}

My Question is:我的问题是:

Is the rset object automatically converted as transient at compile- or run-time? rset对象是否在编译时或运行时自动转换为transient or do I have to mark it explicitly as transient ?还是我必须将其明确标记为transient (That is a warning brought up from my IDE JDeveloper). (这是我的 IDE JDeveloper 发出的警告)。

No, the field is not neglected by serialization - you'll get a java.io.NotSerializableException if you try to serialize an instance of FileDownload .不,序列化不会忽略该字段 - 如果您尝试序列化FileDownload的实例,您将得到java.io.NotSerializableException Mark it transient .将其标记为transient Btw, what is a ResultSet doing as a field in a Servlet ?顺便说一句, ResultSet作为Servlet中的字段做什么? This is not thread-safe.这不是线程安全的。 ResultSets should be local variables only, in any context.在任何上下文中, ResultSets都应该只是局部变量。

You have to call transient your own.But you cannot serialize an object unless it implements Serializable interface.ResultSet is such kind of object.你必须自己调用transient 。但是你不能serialize一个对象,除非它实现了Serializable接口。ResultSet 就是这样一种对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 可序列化类中的非瞬态不可序列化实例字段 - Non-transient non-serializable instance field in serializable class 如何处理 Findbugs“可序列化类中的非瞬态不可序列化实例字段”? - How to handle a Findbugs “Non-transient non-serializable instance field in serializable class”? 实体 class 定义非瞬态不可序列化实例字段价格 - Entity class defines non-transient non-serializable instance field price 具有实用程序静态方法的类给出了非瞬态不可序列化的实例字段错误 - Class with utility static method gives Non-transient non-serializable instance field error 不可序列化父类的可序列化子类 - Serializable subclass of non-serializable parent class 形成复合键的持久类属性是否还需要可序列化或在不可序列化的情况下是瞬态的? - Do persistent class properties forming composite key also need to be serializable or transient in case of non-serializable? 在Serializable类中使用transient关键字 - Use transient keyword in not Serializable class 序列化包含非可序列化类的类 - Serializing a class containing a non-serializable class 如果我没有在Java中将不可序列化的字段标记为瞬态怎么办? - What happens if i don't mark a non-serializable field as transient in java? 当使用可序列化的非引用字段将序列化的类序列化为null时,不会引发任何异常 - No Exception is thrown when a serializable class is serialized with a Non-serializable reference field value is null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM