Home » Java » Java VM doesn't work with `android.util.*`: Mutable classes cannot be initialized with value other than zero

Java VM doesn't work with `android.util.*`: Mutable classes cannot be initialized with value other than zero

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am using Android Studio 3.1.2 with API level 26 and min API 21. I checked and saw that package android.util has type MutableDouble with implementation like this:

package android.util;

/**
 */
public final class MutableInt {
  public int value;

  public MutableInt(int value) {
    this.value = value;
  }
}

But when I initialize new instance of MutableDouble with specific input value, it always receives zero value like this:

MutableDouble d = new MutableDouble(999d);
System.out.println("Received value: " + d.value);
=> "Received value: 0.0"

I have to set the value directly to make it work

MutableDouble d = new MutableDouble(999d);
d.value = 777d;
System.out.println("Received value: " + d.value);
=> "Received value: 777.0"

I have copied above implementation of MutableDouble to my own project and it worked as expected.

Checking other similar classes like MutableInt, MutableFloat, etc. and they have the same issue.

Did anyone face this issue like me? Any wrong configuration in Android Studio causes this?

Answers: