开发者

Can Linux Java Developers create classes of names different only by case in the same package?

开发者 https://www.devze.com 2023-02-07 04:43 出处:网络
In Java class names are supposed to be 开发者_如何学Pythoncase sensitive, so Java shouldn\'t have a problem with it. The problem should come from case-insenstive file systems, many linuxes not include

In Java class names are supposed to be 开发者_如何学Pythoncase sensitive, so Java shouldn't have a problem with it. The problem should come from case-insenstive file systems, many linuxes not included.


I tried this on Linux, and I could create different classes with same name but different capitalization and use them. As I have no Windows-machine, I can't test how this would work (or if it works at all) in Windows (or any other OS for that matter), but I would not encourage naming classes like this.


What are you talking about?

The class name is not derived from the filename but from the contents of the file (i.e. the class name as it appears in the file).

Whether the filesystem or OS treat filenames as case insensitive is irrelevant.


You can't by official naming convention. You must name your class using CamelCase, starting with a Uppercase.

In Linux you can do it, but it's a very bad idea. Your resulting code/classes will not be portables.

And you will found problems with source control tools, IDE's, another OSes, some JVMs, etc.

For example: you can use non-english (utf8) characters for your classes. I have seem classes with Spanish names (with characters like ñ, Ñ, á, à, etc). Soon or later it will be a problem, because not every filesystems works with utf8 (some uses ansi-like, ascii, or something else). Very long names can be trouble too. Some filesystems have limits on name length like ISO-9660 filesystems, some FAT versions, etc.

Stay in the safe path :)

0

精彩评论

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

关注公众号