为什么 NSNumber 是不可变的? [英] Why is NSNumber immutable?

查看:59
本文介绍了为什么 NSNumber 是不可变的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么 NSNumber 是不可变的?有充分的理由吗?因为现在我正在考虑创建自己的类只是为了可变性.

Why is NSNumber immutable? Was there a good reason? Because now I am thinking about creating my own class just for the sake of mutability.

推荐答案

数字是一种非常基本的数据类型.一个数字就是——一个数字.如果你改变它,它只是碰巧是别的东西.一个数字根本无法改变.

A number is a very basic data type. A number is just that - a number. If you mutate it, it just happens to be something else. A number simply cannot change.

将其与更复杂的数据进行比较,其中对象本身仍然代表相同的事物.

Compare that with more complex data, where the object itself still represents the same thing.

这篇关于为什么 NSNumber 是不可变的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆