sergionni
sergionni

Reputation: 13530

Naming for static final fields of java.io.File are not standard

I'm preparing to SCJP and have observed interesting thing.

Sun naming conventions are not followed for constants:

File.separatorChar
File.separator
File.pathSeparatorChar
File.pathSeparator

How it can be explained?

Perhaps, some historical issue or just typo?

Upvotes: 1

Views: 215

Answers (1)

ColinD
ColinD

Reputation: 110094

None of those are constants, technically (see the definition of a constant expression). A constant's value is known at compile time. I believe that the uppercase-with-underscores naming convention only applies to actual constants and not just any static final field. As to why they aren't constants, they are of course file system dependent and have to be looked up for the current file system at runtime.

(It is, though, very common in Java code to use the same naming convention for all static final fields regardless of whether they're technically constants or not.)

Upvotes: 4

Related Questions