简体   繁体   中英

Kotlin: What is the difference between = vs ==?

I'm trying to set a certain value, monsterHealth , to display 0 instead of a negative number. If I'm trying to reassign the value to show 0 instead of, say, -2 , would I want to use = or == ?

Those are different operators:

  • = - assignment operator,
  • == and != - equality operators,
  • === and !== - referential equality operators.

also

  • val - read only variable/property (it cannot be reassigned/changed),
  • var - mutable variable/property.

Kotlin Documentation - Keywords and operators

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM