编译Java时的debug信息对class文件大小的影响

-rw-rw-r– 1 jialiang users 107 Jul 22 11:20 Bar.java
[jialiang@root java_debug_flag]$ javac -g:none Bar.java
[jialiang@root java_debug_flag]$ ls -ort
total 8
-rw-rw-r– 1 jialiang 107 Jul 22 11:20 Bar.java
-rw-rw-r– 1 jialiang 488 Jul 22 11:21 Bar.class
[jialiang@root java_debug_flag]$ javac -g:vars Bar.java
[jialiang@root java_debug_flag]$ ls -ort
total 8
-rw-rw-r– 1 jialiang 107 Jul 22 11:20 Bar.java
-rw-rw-r– 1 jialiang 591 Jul 22 11:22 Bar.class
[jialiang@root java_debug_flag]$ javac -g:vars,lines Bar.java
[jialiang@root java_debug_flag]$ ls -ort
total 8
-rw-rw-r– 1 jialiang 107 Jul 22 11:20 Bar.java
-rw-rw-r– 1 jialiang 629 Jul 22 11:22 Bar.class
[jialiang@root java_debug_flag]$ javac -g:vars,lines,sources Bar.java
[jialiang@root java_debug_flag]$ ls -ort
total 8
-rw-rw-r– 1 jialiang 107 Jul 22 11:20 Bar.java

-rw-rw-r– 1 jialiang 629 Jul 22 11:22 Bar.class

从上面的例子可以看出,没有debug信息的class文件和所有debug信息class文件的增量比是:(629-488)/488=28%

PS:在eclipse中如果开启-g:vars,lines,source


http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Freference%2Fpreferences%2Fjava%2Fref-
preferences-compiler.htm