Does Java include comments on the compiled code?

2020-03-14 02:09发布

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

5条回答
神经病院院长
2楼-- · 2020-03-14 02:40

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.

查看更多
Root(大扎)
3楼-- · 2020-03-14 02:50

No, this is not added.

However, you should consider to kill dead code (i.e. 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...

查看更多
兄弟一词,经得起流年.
4楼-- · 2020-03-14 02:54

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

查看更多
Rolldiameter
5楼-- · 2020-03-14 02:55

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.

查看更多
男人必须洒脱
6楼-- · 2020-03-14 02:55

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.

查看更多
登录 后发表回答