Java:静态瞬态字段 [英] Java: Static transient fields

查看:86
本文介绍了Java:静态瞬态字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Java中发现您可以声明一个字段静态瞬态"-编译器不会抱怨.众所周知,这似乎没有任何用处,因为静态字段没有序列化.

I just found out in Java you can declare a field 'static transient' - the compiler doesn't complain. This doesn't seem to be useful in any way since static fields are not serialized, as we all know.

但我想知道,实际上是否存在静态瞬态"字段有用的情况?

But I wonder, is there actually a case where 'static transient' fields are useful?

推荐答案

不是-您自己说过,静态字段未序列化.

Nope - you said it yourself, static fields aren't serialized.

Kinda很奇怪,编译器允许您这样做.

Kinda weird that the compiler lets you do that though.

这篇关于Java:静态瞬态字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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