Why NSNumber points to the same address when value are equals?

前端 未结 3 870
心在旅途
心在旅途 2020-12-10 15:39

Given the following code:

int firstInt, secondInt;

firstInt = 5;
secondInt = 5;

NSNumber *firstNumber = [NSNumber numberWithInt:firstInt];
NSNumber *second         


        
3条回答
  •  清歌不尽
    2020-12-10 16:08

    Because they have the same hash value, so NSNumber gives back to you a cached pointer from the first allocation.

提交回复
热议问题