可变和不可变之间有什么区别 [英] what is difference between mutable and immutable

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

问题描述

什么是可变和不可变的区别

what is difference mutable and immutable

喜欢

NSString和NSMutableString。

NSString and NSMutableString.

NSArray和NSMutableArray。

NSArray and NSMutableArray.

NSDictionary和NSMutableDictionary。

NSDictionary and NSMutableDictionary.

有什么区别可变对象和另一个对象之间[我猜不可变]

What is difference between mutable object and the other object[which i guess immutable]

@thanks提前。

@thanks in advance.

推荐答案

可以改变或改变可变对象。不可变对象不能。例如,虽然您可以在NSMutableArray中添加或删除对象,但您无法使用NSArray。

A mutable object can be mutated or changed. An immutable object cannot. For example, while you can add or remove objects from an NSMutableArray, you cannot do either with an NSArray.

可变对象可以更改,添加或删除元素,使用不可变对象无法实现。在 [[object alloc] initWith ...] 初始值设定项中,不可变对象会被你提供的任何输入所困。

Mutable objects can have elements changed, added to, or removed, which cannot be achieved with immutable objects. Immutable objects are stuck with whatever input you gave them in their [[object alloc] initWith...] initializer.

你的可变对象的优点是显而易见的,但它们只应在必要时使用(这比你想象的要少得多),因为它们占用的内存比不可变对象多。

The advantages of your mutable objects is obvious, but they should only be used when necessary (which is a lot less often than you think) as they take up more memory than immutable objects.

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

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