aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Ternary Operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Ternary Operator" Watch "Ternary Operator" New topic
Author

Ternary Operator

Saibabaa Pragada
Ranch Hand

Joined: Oct 24, 2010
Posts: 162
Can you tell me where I am going wrong with this ternary operator ?..After "?" mark, should I keep only Strings ??
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

Exp1 is giving out "boolean" type and Exp2 gives out an integer value... So its a type mismatch

the expressions should be evaluated to give "String" type objects..


SCJP 6 [SCJP - Old is Gold]
Prasad Kharkar
Ranch Hand

Joined: Mar 07, 2010
Posts: 438

we are declaring variable first2 as String so the ternary operator should return String type value but you are returning boolean if the condition is true and an integer if the condition is false
to clear this, either convert them to String or declare first2 as Object like this

hope this helps


SCJP 6 [86%] June 30th, 2010
OCPWCD [84%] March 26th, 2013
If you find any post useful, click the "plus one" sign on the right
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Put simply (in my eyes) Your ternary expression appears to be assigning a boolean or an integer to a String reference variable, thats all.



be a well encapsulated person, don't expose your privates, unless you public void getWife()!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Ternary Operator
 
Similar Threads
Ternary
can any one explain this
return null from primitive method
ternary operation
why to use conditional operator " ? " ?