Is Java transient keyword syntactic sugar?

Akshaya Shanbhogue :

Why wasn't transient solved by using annotations instead of introducing a keyword?

It seems like the transient keyword doesn't really provide any native functionality to the language, and seems to be more syntactic-sugar to prevent accidental serialization.

Am I missing something?

user7294900 :

Java transient keyword was added from the first java version, while Annotations was added later in 1.5 version

Actually transient uses ad hoc annotation mechanism:

Java platform has always had various ad hoc annotation mechanisms. For example the transient modifier is an ad hoc annotation indicating that a field should be ignored by the serialization subsystem

Notice the Scala has @transient and also volatile:

@transient Marks a field to be non-persistent; this is equivalent to the transient modifier in Java.

@volatile Marks a field which can change its value outside the control of the program; this is equivalent to the volatile modifier in Java.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=99246&siteId=1