• 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

Assertion

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

I have confusion in assertion statement.

assert Expression1:Expression2;

aseert statement should not change or alter the value of any variable.

so,

assert i%2==0:i++; //line 1


assert i<100:i=i%100; //line 2


assert x-->0; //line 3



According to me all the three statement give compile time error as they are altering the values.
Am I right?

one more thing:
At compile time the compiler look for the complete assert statement means both Expression1 and Expression 2 and if any statement alter the value(any side effect found) will give compiler error.

Am I right?

Correct me.

Thanks
sandhi
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's an idea to find the answer: Write a small test program, try to compile it, see if the compiler reports any errors or not.

Experimenting yourself is a very good way to learn how Java works.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic