简体   繁体   English

当java(解释器)区分大小写时,为什么Java编译器(javac)不区分大小写?

[英]Why is the Java compiler (javac) case-insensitive when java (the interpreter) is case-sensitive?

When I was executing a Java program I noticed that the Java compiler is case-insensitive with respect to file names whereas the Java interpreter is case-sensitive. 当我执行Java程序时,我注意到Java编译器在文件名方面不区分大小写,而Java解释器区分大小写。

The Java interpreter being case-sensitive is very much understandable as, the name of the class file is the name of the class defined in the Java code. Java解释器区分大小写是非常容易理解的,因为类文件的名称是Java代码中定义的类的名称。

Is there any good reason for the Java compiler being case-insensitive? Java编译器是否有任何不恰当的原因?

The Windows filesystem is case-insensitive. Windows文件系统不区分大小写。
You cannot (sanely) find a case-sensitive file on a case-insensitive filesystem. 您不能(合理地)在不区分大小写的文件系统上找到区分大小写的文件。

If you run javac on Linux with a case-sensitive filesystem, it will be case-sensitive. 如果您在Linux上使用区分大小写的文件系统运行javac ,它将区分大小写。

it depends on the underlying file system. 它取决于底层文件系统。 Windows' file system is not case sensitive, so the when the java compiler looks for 'Foo.java', the OS will happily open 'foo.java' instead. Windows的文件系统不区分大小写,因此当java编译器查找“Foo.java”时,操作系统将很乐意打开'foo.java'。

Presumably you're running the compiler on Windows or another operating system with either a case-preserving or case-insensitive filesystem. 据推测,您正在Windows或其他操作系统上运行编译器,其中包含保留大小写或不区分大小写的文件系统。 If you ran it on an OS that used a case-sensitive filesystem, you would get different results. 如果您在使用区分大小写的文件系统的操作系统上运行它,您将得到不同的结果。 In other words, it's not the compiler, it's the operating system (or rather, its filesystem). 换句话说,它不是编译器,而是操作系统(或者更确切地说,它的文件系统)。

Windows is still an OS for children and people that just want to surf the Web or do their fiscal paperwork. Windows仍然是一个面向儿童和人们的操作系统,他们只想上网或做财务文书工作。 But not for developers. 但不适合开发人员。

Since almost 20 years, MS has done almost nothing with respect to: 近20年来,MS在以下方面几乎没有做任何事:

  • File systems (they could keep their beloved NTFS as default, and offer another one for professionals, could they not) 文件系统(他们可以保持他们心爱的NTFS默认,并为专业人士提供另一个,他们不能)
  • Command line, it's still the same bad crap we got with Windows NT. 命令行,它仍然是我们用Windows NT得到的坏垃圾。 Mind you, NT stands for "New Technology" and yet they didn't even manage to inherit what was already available for another 10 or 20 years. 请注意,NT代​​表“新技术”,但他们甚至没有设法继承已有的10年或20年。

Hence, if you develop Java, make sure you don't have class or package names that differ in case only. 因此,如果您开发Java,请确保您没有仅在大小写不同的类或包名称。 This will invariably lead to disaster. 这将不可避免地导致灾难。

Do yourself a favor, make a bit room on your HD, or attach an external one, and install a dual boot LINUX. 帮自己一个忙,给你的HD留一点空间,或者连接一个外置的,并安装双启动LINUX。 If must be, make a virtual machine. 如果必须,请创建一个虚拟机。 You'll never look back, once you got your favored IDE installed. 一旦安装了您喜爱的IDE,您将永远不会回头。 And you'll learn a bit or two along the way. 而且你将在此过程中学到一两点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM