开发者

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

开发者 https://www.devze.com 2023-02-28 08:38 出处:网络
I\'m preparing to SCJP and have observed interesting thing. Sun naming conventions are not followed for constants:

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.)

0

精彩评论

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