java - Compiling without assertions -


i know assertions can enabled/disabled @ runtime debugging , production, respectively. found assertions increase size of generated binary (about 100-200 bytes in example below).

in c , c++, can @ compile time having #define ndebug before #include <assert.h>.

is there way java compiler automatically this? i'd leave them in source code debugging purposes later on. don't want resultant binary larger necessary (we have size limit design requirement).

c code:

//#define ndebug #include <assert.h>  int main(void) {     assert(0); // +200 bytes without ndebug, 0 ndebug     return 0; } 

java code:

public class test {     public static void main(string[] args) {         assert(system.nanotime()==0); // increases binary size 200 bytes     } } 

in response bn.'s answer:

public class test2 {     public static final boolean assertions = false;      public static void main(string[] args) {         if(assertions) {             assert(system.nanotime()==0);         }     } } 

edit: in fact, seems me enabling/disabling more useful compile-time feature run-time. mean, how many end users enable them? far programmer concerned during debug process, he/she recompiling code anyways.

personally not following because of complexity added source code javac generated exact same intermediate code main in following 2 fragments:

conditional asserts

class c {     public final static boolean assertions = false;      public static void main(string[] args) {         if(assertions) {             assert(system.nanotime()==0);         }     } } 

no asserts

class c {     public static void main(string[] args) {     } } 

compiled code

  public static void main(java.lang.string[]);     code:        0: return             linenumbertable:       line 3: 0 

edit

in fact, seems me enabling/disabling more useful compile-time feature run-time. mean, how many end users enable them?

its not end users enable them, customer support tells end user enable them. wish though enabled, not disabled, default.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -