Ternary operator...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   rajesh_tiwari
Posted On:   Monday, August 5, 2002 01:27 AM

As per the synatx of using ternary operator : boolean-expr ? value1 : value2; value1 will be eavaluate if boolean expression returns true and vice versa. I have given one expression like following : ((someObj.someMethod()) ? ps.setString (5, 'Y') : ps.setString(5, 'N')); But the JDK compiler reports : someDAO.java:98: not a statement ((contractorValue.getSafetyProgramIn() == true) ? ^ Please note here that someMethod() returns boolean value... Any input..... Jesh    More>>

As per the synatx of using ternary operator :

boolean-expr ? value1 : value2;

value1 will be eavaluate if boolean expression returns true and vice versa.



I have given one expression like following :

((someObj.someMethod()) ? ps.setString (5, 'Y') : ps.setString(5, 'N'));



But the JDK compiler reports :

someDAO.java:98: not a statement
((contractorValue.getSafetyProgramIn() == true) ?
^


Please note here that someMethod() returns boolean value...


Any input.....


Jesh

   <<Less

Re: Ternary operator...

Posted By:   Anonymous  
Posted On:   Monday, August 5, 2002 02:31 AM

The compiler says you cannot use a ternary operator as a statement, which means a conditional method call in your case. It is only indented for conditional parameters, e.g. System.out.println(true?"true":"false");


Whats wrong with if()? Why don't you use that?

About | Sitemap | Contact