• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Assertions at compilation time?

 
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
Having had a look to this topic: https://coderanch.com/t/419627/vc/Enable-assertion-complie-time I see that it's possible to enable assertions at compilation time.
I am using Java 7 on ubuntu 12.04 and I cannot do that. i.e. I get "-ea invalid flag".
What am I doing wrong? and moreover why would be useful at all enabling assertions at compilation time?
Thanks in advance.
 
Saloon Keeper
Posts: 3946
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nick Widelec wrote:
I am using Java 7 on ubuntu 12.04 and I cannot do that. i.e. I get "-ea invalid flag".
What am I doing wrong? and moreover why would be useful at all enabling assertions at compilation time?
Thanks in advance.



Hi,

Assertions can be enable/disabled at run time, not at compile time. The compiler complains correctly in your case...

So, instead of



you should use:



Please, refer this article for details.

Best regards,
MZ
 
Nick Widelec
Ranch Hand
Posts: 226
Eclipse IDE Firefox Browser Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mikalai Zaikin wrote:

Nick Widelec wrote:
I am using Java 7 on ubuntu 12.04 and I cannot do that. i.e. I get "-ea invalid flag".
What am I doing wrong? and moreover why would be useful at all enabling assertions at compilation time?
Thanks in advance.



Hi,

Assertions can be enable/disabled at run time, not at compile time. The compiler complains correctly in your case...

So, instead of



you should use:



Please, refer this article for details.

Best regards,
MZ



Hi thanks for responding,
What about the link I posted in my original post?
 
Mikalai Zaikin
Saloon Keeper
Posts: 3946
43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no such thins as "enabling/disabling assertions at compile time".

You may be confused by how compilers treat the "assert" word at compile time.

With Java SE 1.3 and earlier, the word "assert" is not reserved one, i.e. can be used as variable name.

With Java SE 1.4 and later (including Java SE 7) the word "assert" is reserved one, and *always* will be used for assertions.

So, if you need to compile Java source code which contains variable names with "assert" in Java SE 7, you need to tell compiler to treat source code as old one, and you can do it with the "-source" argument:



But this is not "disabling assertions" activity, this is "informing compiler to treat assert as valid variable name" activity.

HTH,
MZ
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic