开发者

Transients in Java

开发者 https://www.devze.com 2023-02-23 13:21 出处:网络
I was looking at JOptionPane.java. On line 387 there is transient protected Objectand on line 399 ther开发者_开发百科e is protected transient Object.

I was looking at JOptionPane.java. On line 387 there is

transient protected Object
and on line 399 ther开发者_开发百科e is
protected transient Object
.

What is the difference between the two?


None. Just poor coding standards. On your code try to use the 2nd one.


The second one follows the code conversion, the first one doesn't. They are equivalent.


No difference. This order doesn't matter.


According to the JLS, http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.3.1

8.3.1 Field Modifiers

FieldModifiers:
  FieldModifier
  FieldModifiers FieldModifier

FieldModifier: one of
  Annotation public protected private
  static final transient volatile

If two or more (distinct) field modifiers appear in a field declaration, it is customary, though not required, that they appear in the order consistent with that shown above in the production for FieldModifier.

So it would appear the second one is more conventional.


No, the order of these keywords does not matter. See this article on the transient keyword for more information.

0

精彩评论

暂无评论...
验证码 换一张
取 消