• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Output of this code

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


I thought the output was AssertionError with "assertion passed" message. But the code did not compile itself. It gave the following errors.

incompatabile types.
found : java.lang.String
required: boolean

Can someone tell me why?

Thanks.
 
author
Posts: 23912
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Can someone tell me why?



You might want to read the docs about assertions again. Something tells me that you did not intend to use the Ternary operator with Assertions.

Henry
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arjun, assertion expressions can be of 2 forms:

1) assert exppression1; (exppression1 should be boolean)

2)assert exppression1: expression2; (exppression1 should be boolean and expression2 should return a value which will be displayed when an Assertion Error occurs)
 
Sheriff
Posts: 9691
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your code is working like this

int x = 0;
assert ((x > 0)? "assertion failed" : "assertion passed");

so actually what happens is, since x is 0, so the statement will look like this

assert "assertion passed".
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, I got it.
[ September 23, 2008: Message edited by: Arjun Reddy ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic