• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ternary Operator

 
Saibabaa Pragada
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 247
Chrome Eclipse IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stephen Davies
Ranch Hand
Posts: 352
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put simply (in my eyes) Your ternary expression appears to be assigning a boolean or an integer to a String reference variable, thats all.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic