Why strings does not compare references?

后端 未结 5 1084
耶瑟儿~
耶瑟儿~ 2021-01-11 23:54

I know it is special case but why == between strings returns if their value equals and not when their reference equals. Does it have something to do with overlloading operat

5条回答
  •  伪装坚强ぢ
    2021-01-12 00:28

    Because strings are immutable and the runtime may choose to put any two strings with the same content together into the same reference. So reference-comparing strings doesn't really make any sense.

提交回复
热议问题