简体   繁体   中英

Does Java include comments on the compiled code?

Well, the title is self-explanatory. I wondered this while compiling a project which has a lot of lines commented. It's a bit silly because the jar file wouldn't increase much (some bytes) but I'm curious if this could affect a program with a lot of code and comments.

Thanks

No, comments normally are stripped out in any language (not just in Java). They have no representative in byte code. What stays in there, is annotated stuff and such

It would not affect the execution or performance (unless you have commented out the wrong statements :-)

But it definitely would affect readability. There is no reason to have large blocks of commented out code (in production), version control is the way to go

See this question also. Question closed.

No, documentation isn't included in the compiled class file.

The javadocs can be generated with the javadoc program. All javadoc will be converterd to HTML.

No, this is not added.

However, you should consider to kill dead code (ie commented code, but also unused code). If you think that "maybe I will need that method again", simply delete the method, and if you really need this method some day, use you SCM tool (Subversion, Git, CVS or whatever) to retrieve this old code...

Yes JAVA includes comment in the compiled code because without including how it will come to know that whether this is a comment or not . But after including the commented line is not sent to compiler directive for compilation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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