Java: changing the value of the float object

I have looked inside the Javadoc of float, but it seems that there is no way to modify the value after construction?

Float f = new Float(1.23f);
[...]
f.setValue(3.14f); // Nothing like this seems to exist...
f = 3.14f; // "f" Now points to a new object,not what I want...

Is there any way to change the value of the object? Or, is there another wrapper class available that allows this?

Solution

You cannot change the value of float; All original wrapper classes are immutable If you want to add this feature, you can create your own (mutable) wrapper class, or view mutablefloat. Com from Apache Commons

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>