Questions tagged [mutable]

A mutable can be modified after it is created.

A mutable can be modified after it is created. It is a keyword in functional programming opposite to immutable.

Related tags:

1184 questions
-2
votes
1 answer

Instantiating multiple mutable variable

I have instantiated multiple mutable variable: SimpleStringBuffer a=new SimpleStringBuffer(); SimpleStringBuffer b=new SimpleStringBuffer(); I have done this 11 times, I know there is some way to avoid doing it using array or collections but I am…
MR AND
  • 376
  • 7
  • 29
-2
votes
3 answers

How to create a mutable array of specific class type in Swift

I have a class called Bullet and I want to make a mutable array with this class type. Basically the desired outcome I want is, when a user touches the screen a new bullet is spawned. I know in Java you can use an ArrayList to achieve this by adding…
Stephen Fox
  • 14,190
  • 19
  • 48
  • 52
-2
votes
1 answer

Java object not added to ArrayList

I have a problem. I am writing code for an ecosystem with fish and I am trying to add a new Fish object to an existing fish ArrayList . However, when I check the ArrayList it turns out to be empty? Thoughts? public void addFish(Fish f){ …
anubie
  • 21
  • 1
-3
votes
1 answer

Is changing a variable in a recursive call considered mutation

My goal is to sum a list without using mutation. def noMutObj(lst,pointer=0, result=0): if pointer == len(lst): return result newResult = result + lst[pointer] return noMutObj(lst, pointer+1, newResult) Would we consider…
Artemis
  • 139
  • 12
-3
votes
2 answers

Functional Programming Book (O'reilly): Mutable List Example: True or False

I am reading the Book O'reilly Functional Programming for Java Developers from Dean Wampler. On the page 9, It uses an example titled: "Consider the following example, where a mutable List is used to hold a customer's orders: public class Customer…
Marlhex
  • 1,870
  • 19
  • 27
-3
votes
1 answer

How to use the UnsafeMutablePointer in Swift 3?

if let fileObject = NSString(contentsOfFile: strBundle, usedEncoding:Int32? Every time that I try to work this out, I get more frustrated! Please help me! I am not sure what I need to fill in the "usedEncoding:" parameter. Here is the error it…
-3
votes
1 answer

in Java, why it is recommended to use equals() when comparing mutable objects?

I read that usually we use equals() for comparing immutable object, where == is used for mutable object I know the differences between equals and "==", but why it is preferred to use equals for immutable objects? and why using "==" for mutable…
Matt. Stroh
  • 904
  • 7
  • 16
-3
votes
1 answer

Is there a better alternative to keeping a mutable optional argument as a parameter without its value persisting on subsequent calls in Python?

Inappropriately marked as a duplicate question. This has nothing to do with not knowing how to pass a variable by reference. It is asking if there is a way to mitigate the issues with keeping a mutable optional argument as a parameter without its…
Dan Chrostowski
  • 337
  • 2
  • 8
-3
votes
2 answers

Unable to update a mutable Scala collection inside a loop (or map)

I have a mutable scala Set: val valueSet = scala.collection.mutable.Set[Int](0, 1, 2) when I perform valueSet -= 1 the result is Set(0,2) But when I perform same thing inside a loop or map: Range(0, 10).map(entry => valueSet -=…
Shashi K
  • 55
  • 8
-3
votes
2 answers

Scala best way of turning a Collection into a mutable Map-by-key

Here is example of building immutable Map from colleciton. How to do the same but for mutable? (without converting resulting immutable Map to mutable one)
Cherry
  • 31,309
  • 66
  • 224
  • 364
-3
votes
1 answer

Pass by value or Pass by reference in Java: Issues with immutable and mutable objects

Is java pass by value or pass by reference. My question induced me to write this class so that I may confidently answer. As I was wondering I noticed there might be issue with immutable and mutable object. what I am asking is what is the right…
LeandreM
  • 943
  • 3
  • 12
  • 24
-4
votes
1 answer

Does a mutable Java object equal itself?

I was thinking about mutable objects and how they're weird (but very cool). Question: can a mutable object not equal itself? Only caveat here is that obviously you must override equals method, otherwise the default checks pointer equality which will…
Jared
  • 940
  • 5
  • 9
-4
votes
2 answers

which is the better approach to check in const function if something is created or not?

In my code myclass has two two const functions which are being called by some other const functions. In this class I am not modifying anything except bool variable. In this code bool variable "isCreated" is being used to check if something is…
-6
votes
2 answers

Why it is important to make mutable data members of a Java class Private

Why it is important to make mutable data members of a Java class private? What consequences does this have, and how do we commonly get around them? Appreciate any help. Have been googling around but I've only came across answers that explain how to…
1 2 3
78
79