Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Constant - Char & String  RSS feed

 
Niyas Ahmed Sheikh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Output:
false true false true false false

For me it seems to be true for all the things? How the output comes like that? Can anyone explain why?
 
Norm Radder
Ranch Foreman
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to read the doc for the == operator.
What is it comparing when the operands are objects?
For compairing objects, use the equals() method.

Because of the way the JVM uses strings, sometimes two String references will be == but not in general.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!