【发布时间】:2014-01-09 03:11:51
【问题描述】:
我有一个与 transient 关键字在 java 中 private 修饰符之前的使用有关的问题。
变量声明:
transient private ResourceBundle pageResourceBundle;
我的班级是这样的:
public class LoginViewModel extends AbstractViewModel {
transient private ResourceBundle pageResourceBundle;
@AfterCompose
public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {
initializeLoginValues();
boolean timeout = BooleanUtils.toBoolean(getHttpServletRequest().getParameter("timeout"));
if (timeout) {
Messagebox.show(pageResourceBundle.getText("MSG_SESSION_HAS_EXPIRED_PLEASE_LOGIN"), pageResourceBundle.getText("LABEL_ALERT"),
Messagebox.OK, Messagebox.ERROR);
}
view.getPage().setTitle(CsdcLicence.get().getApplicationName());
}
我有一些问题。
1.为什么在私有变量前使用transient关键字?
2.使用这个关键字的目的是什么?
【问题讨论】:
-
您提供的链接回答了您的两个问题。你有什么疑问?哪些内容尚未涵盖?
-
@PeterLawrey 编辑我的问题,请查看我的课程,它没有实现序列化
-
您的类可能会被您正在使用的库序列化,或者
transient可能会被您与模型一起使用的库用于其他目的。它可能会在视图中显示除transient之外的所有字段。您必须阅读您正在使用的库的文档。 -
有人能解释一下为什么我们要故意通过网络丢失对象吗?有什么例子吗?
标签: java serialization keyword transient modifier