mutable

Cocoa: Testing to find if an NSString is immutable or mutable?

空扰寡人 提交于 2019-11-29 04:26:47
This produces an immutable string object: NSString* myStringA = @"A"; //CORRECTED FROM: NSMutableString* myStringA = @"A"; This produces a mutable string object: NSMutableString* myStringB = [NSMutableString stringWithString:@"B"]; But both objects are reported as the same kind of object, "NSCFString": NSLog(@"myStringA is type: %@, myStringB is type: %@", [myStringA class], [myStringB class]); So what is distinguishing these objects internally, and how do I test for that, so that I can easily determine if a mystery string variable is immutable or mutable before doing something evil to it? The

Converting mutable to immutable map

安稳与你 提交于 2019-11-29 04:23:21
问题 private[this]object MMMap extends HashMap[A, Set[B]] with MultiMap[A, B] How convert it to immutable? 回答1: The immutable hierarchy doesn't contain a MultiMap, so you won't be able to use the converted structure with the same convenient syntax. But if you're happy to deal with key/valueset pairs, then: If you just want a mutable HashMap , you can just use x.toMap in 2.8 or collection.immutable.Map(x.toList: _*) in 2.7. But if you want the whole structure to be immutable--including the

The final word on NSStrings: Mutable and Immutable

杀马特。学长 韩版系。学妹 提交于 2019-11-29 04:18:52
I've read in several books... and online... about immutable and mutable strings. They claim "immutable strings" can't be changed. (But they never define "change".) Which of these NSStrings could be changed without using NSMutableString? The string contains "catfish"... and I later try to change it to "cat". (Same letters, just shorter.) It contains "cat"... and I try to change it to "catfish". (Similar start... but just made longer.) I change "cat" into "CAT". (Same letters, but just the case has changed.) I change "cat" into "dog". (Totally different string, but the same length.) I change

mutable fields for objects in a Java Set

ε祈祈猫儿з 提交于 2019-11-29 03:53:59
Am I correct in assuming that if you have an object that is contained inside a Java Set<> (or as a key in a Map<> for that matter), any fields that are used to determine identity or relation (via hashCode() , equals() , compareTo() etc.) cannot be changed without causing unspecified behavior for operations on the collection? (edit: as alluded to in this other question ) (In other words, these fields should either be immutable, or you should require the object to be removed from the collection, then changed, then reinserted.) The reason I ask is that I was reading the Hibernate Annotations

What to return when overriding Object.GetHashCode() in classes with no immutable fields?

无人久伴 提交于 2019-11-29 02:57:28
问题 Ok, before you get all mad because there are hundreds of similar sounding questions posted on the internet, I can assure you that I have just spent the last few hours reading all of them and have not found the answer to my question. Background: Basically, one of my large scale applications had been suffering from a situation where some Binding s on the ListBox.SelectedItem property would stop working or the program would crash after an edit had been made to the currently selected item. I

How I can mutate a struct's field from a method?

蓝咒 提交于 2019-11-29 00:52:28
I want to do this: struct Point { x: i32, y: i32, } impl Point { fn up(&self) { self.y += 1; } } fn main() { let p = Point { x: 0, y: 0 }; p.up(); } But this code throws a compiler error: error[E0594]: cannot assign to field `self.y` of immutable binding --> src/main.rs:8:9 | 7 | fn up(&self) { | ----- use `&mut self` here to make mutable 8 | self.y += 1; | ^^^^^^^^^^^ cannot mutably borrow field of immutable binding Vladimir Matveev You need to use &mut self instead of &self and make the p variable mutable: struct Point { x: i32, y: i32, } impl Point { fn up(&mut self) { // ^^^ Here self.y +=

Is the use of del bad?

允我心安 提交于 2019-11-28 18:33:24
I commonly use del in my code to delete objects: >>> array = [4, 6, 7, 'hello', 8] >>> del(array[array.index('hello')]) >>> array [4, 6, 7, 8] >>> But I have heard many people say that the use of del is unpythonic. Is using del bad practice? >>> array = [4, 6, 7, 'hello', 8] >>> array[array.index('hello'):array.index('hello')+1] = '' >>> array [4, 6, 7, 8] >>> If not, why are there many ways to accomplish the same thing in python? Is one better than the others? Option 1: using del >>> arr = [5, 7, 2, 3] >>> del(arr[1]) >>> arr [5, 2, 3] >>> Option 2: using list.remove() >>> arr = [5, 7, 2, 3]

How to make any view to draw to canvas?

孤街醉人 提交于 2019-11-28 15:21:32
问题 I have a short question: Suppose I have a (mutable) bitmap that I need to modify (add images, texts, etc...) . Instead of messing around with many special classes for drawing to the canvas (paint, canvas, matrices and so on), I was thinking why not use the built in classes of Android for this task and only if i need really customized operations i could still use the canvas ? So, for example, in order to show any kind of view (that has no parent, of course) on the bitmap, I could call the next

Mutable variable is accessible from closure. How can I fix this?

旧巷老猫 提交于 2019-11-28 15:20:36
I am using Typeahead by twitter. I am running into this warning from Intellij. This is causing the "window.location.href" for each link to be the last item in my list of items. How can I fix my code? Below is my code: AutoSuggest.prototype.config = function () { var me = this; var comp, options; var gotoUrl = "/{0}/{1}"; var imgurl = '<img src="/icon/{0}.gif"/>'; var target; for (var i = 0; i < me.targets.length; i++) { target = me.targets[i]; if ($("#" + target.inputId).length != 0) { options = { source: function (query, process) { // where to get the data process(me.results); }, // set max

Are Python Lists mutable?

老子叫甜甜 提交于 2019-11-28 14:13:41
When I type following code, x=[1,2,4] print(x) print("x",id(x)) x=[2,5,3] print(x) print("x",id(x)) it gives the output as [1, 2, 4] x 47606160 [2, 5, 3] x 47578768 If lists are mutable then why it give 2 memory address when changing the list x? You did not mutate (change) the list object referenced by x with this line: x=[2,5,3] Instead, that line creates a new list object and then reassigns the variable x to it. So, x now references the new object and id(x) gives a different number than before: >>> x=[1,2,4] # x references the list object [1,2,4] >>> x [1, 2, 4] >>> x=[2,5,3] # x now