damat-perdigannat
damat-perdigannat

Reputation: 5960

Why is java.io.File's prefixLength transient?

java.io.File's prefixLength can be used as an identifier for what type of path the File contains. Why is the prefixLength field transient?

Upvotes: 1

Views: 226

Answers (1)

pillingworth
pillingworth

Reputation: 3238

transient is used to indicate the field will be ignored by the standard java serialisation process. In this case it is handled explicitly by the readObject() method instead. This, and path are both handled in the same way.

This is so that when objects are serialised between JVMs running on different platforms (Windows, Linux, etc) the path can be normalised using the platforms file system.

Upvotes: 4

Related Questions