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.path开发者_如何学PythonSeparator
How it can be explained?
Perhaps, some historical issue or just typo?
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.)
精彩评论