Do your javadocs get compiled into your class file

2020-04-02 09:10发布

问题:

When you compile your java files, does it also embed your javadocs and comments into the class file?

For example, if you have large javadocs, does it effect the overall size of your class file? Or does the compiler ignore everything beginning with // and /* ?

回答1:

You can tell the compiler to include the sources in the class file (javac -g:source). That means every bit of the source will be added. Comments, code, whitespace, everything.

If you do that, then the size of the source matters. Otherwise, it doesn't.

From a runtime perspective, the difference doesn't matter much.



回答2:

No, comments are not compiled into your class files. This includes JavaDocs.

Instead, you need to use a JavaDoc tool (like Sun/Oracle's) on the source code to generate the documentation.



回答3:

No, the class file is just binary data.

Annotations may be retained (depending on the annotation).

Comments won't affect the size of the class file.