Just for the heck of it, I wrote two Java files, 766 lines in "ScProgCalc.java", and 361 lines in "BdMath.java"; the former uses the latter. When I compiled the two of them together with the Java compiler I downloaded from the Oracle site (version 1.8.0_40), the compiler generates the following ".class" files:
That looks really messy, so I created a "New" directory, copied "ScProgCalc.java" and "BdMath.java" down there, and extracted files "ExponentPower.java", "Mode.java", and "Status.java" from the original two files. Then when I compiled them again there was just one "BdMath.class" file; no "BdMath$ExponentPower.class" file was generated, because that class wasn't in "BdMath.java" any more. Similarly for "ScProgCalc$Mode.class" and "ScProgCalc$Status.class"; they were both replaced by "Mode.class" and "Status.class". But the "ScProgCalc$1.class" file was still there.
I thought that might be because "ScProgCalc.java" was still pretty big, so I extracted some of the functionality from it and created "Help.java" and "InOut.java". Then I took a look and got:
As you can see, the "ProgCalc$1.class" file is still there. (I renamed "ScProgCalc.java" to "ProgCalc.java" to distinguish it from its monolith ancestor.) Does anybody know why the compiler would take an "Abc.java" file and generate both an "Abc.class" file and an "Abc$1.class" file, and what I can do to stop it from happening? What exactly does the "Abc$1.class" do, anyhow?
Kevin Simonson wrote:What exactly does the "Abc$1.class" do, anyhow?
The BdMath$1.class file is the class file for the anonymous inner class of the BdMath class. And the BdMath$ExponentPower.class file is the class file for the ExponentPower inner class (or nested class) of the BdMath class.