• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Assertions Appropriately

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi .
One of the warning about "Using Assertions Appropriately" is "Don't Use Assert Expressions that Can Cause Side Effects!"

Let me explain what understand from this then you can check my understanding whether is true.

l understand from "Don't Use Assert Expressions that Can Cause Side Effects!" sentence that



public void doStuff() {
assert (modifyThings());
// continues on
}

public boolean modifyThings() {
y = x++;
return true;
}


l understand above code that if assertion is enbled depending that value of "y"(in modifyThings() method) will be changed.
Reverse if assertion is disabled depending that value of "y"(in modifyThings() method) will not be changed.

l am right.
Please help.
Thanks...


 
author & internet detective
Posts: 41860
908
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
You are correct. This is a good example of how to use assertions inappropriately.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic