This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes IDEs, Version Control and other tools and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
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 ?
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

Podonga,
Do you have assertions enabled? If assertions are not enabled, they don't do anything.


[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
podonga poron
Ranch Hand

Joined: May 12, 2008
Posts: 55
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 !
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

I'm going to move this to our IDEs forum where people know more about NetBeans.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 20080
    
  30

I think you forgot the actual moving part
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 32507
    
214

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

Sorry. The phone rang and then I forgot about it
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Assertions
 
It's not a secret anymore!