This week's book giveaways are in the Jython/Python and Object-Oriented programming forums. We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line! See this thread and this one for details.
Normally, .class files retain the name of the original .java file (i.e. foo.java creates a foo.class). When I compile my AbstractSyntax.java file, it changes in to a Assignment.class file. Why might this be happening?
Yeah. The class file in question has a bunch of different separate classes in it. One of the classes is which inherits the code from . The Assignment class is nowhere near the top of the file. Why do you think the interpreter chose that as the name of the class file?
The javac tool isn't an interpreter. The rules are that the file name must match the name of all public top‑level classes in it, which means all the public classes would have to have the same name, so you can only fit one public top‑level class into an XYZ.java file. Same name as the file. Whether it is good design or not, you are allowed multiple non‑public top‑level classes, but the javac tool produces one XXX.class file for each declared class. And those files have the same names as the classes they are compiled from (plus .class). The files have those names because they match the names of the classes you wrote.
If your AbstractSyntax.java file contained a class called AbstractSyntax, then there should be an AbstractSyntax.class file generated. However, it looks like that's not the case. Your AbstractSyntax.java file has many other classes in it, but none are actually called AbstractSyntax. That is, your file does not contain a declaration like this, right?
posted 2 weeks ago
Correct, there is no AbstractSyntax class in the AbstractSyntax.java file.
Also, there are like twenty classes in that file and I didn't see a .class file created for any of them except Assignment.
It might help if you posted the source for your AbstractSyntax.java here so people can look at it instead. Without seeing the source, people are either going to guess or assume. Neither is optimal for figuring out what the real problem is. And please UseCodeTags when you post code.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
I apologize. It looks like compiling AbstractSyntax.java DID create a class file for each class contained within AbstractSyntax.java. I must have been really tired because I didn't notice that. Thank you all for the help!
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads: