Win a copy of Spring Boot in Practice this week in the Spring forum!
  • 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
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Assertions

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading a book who tells if i do an assertion and the assertion is NOT true, the program stop executing and an error (AssertionError) is throw ..

is this correct ?

because when i tryed in NetBeans ..

int a = 8;
assert(a==2); NOTHING HAPPEN

how this work ?
 
author & internet detective
Posts: 41185
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Podonga,
Do you have assertions enabled? If assertions are not enabled, they don't do anything.
 
podonga poron
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i think they are not enabled

do you know how to enable in netbeans ? i need to practice ... and compiling using javac -ea every time is tedious !
 
Sheriff
Posts: 22665
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't compile using the -ea flag, you run it using the -ea flag. The assertions are compiled into the code regardless of the flags.

Isn't there a way to tell NetBeans to run your code with assertions enabled?

As a side node, you do know that your code should work just the same with and without assertions enabled? You can't assume that somebody else will also have assertions enabled when he/she runs your code.
 
Jeanne Boyarsky
author & internet detective
Posts: 41185
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm going to move this to our IDEs forum where people know more about NetBeans.
 
Rob Spoor
Sheriff
Posts: 22665
127
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you forgot the actual moving part
 
Jeanne Boyarsky
author & internet detective
Posts: 41185
848
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Prime:
I think you forgot the actual moving part


Sorry. The phone rang and then I forgot about it
 
reply
    Bookmark Topic Watch Topic
  • New Topic