Java 是否具有 Integer、Float、Double、Long 的可变类型?
我想使用 Integer 之类的可变版本.我必须使用这些类(如下)还是 Java 有内置的东西?
I am in a situation where I want to use mutable versions of things like Integer. Do I have to use these classes (below) or does Java have something built in?
http://www.java2s.com/Code/Java/数据类型/Amutableintwrapper.htm
推荐答案
不,Java 没有这些内置功能.这是有原因的.使用可变类型是危险的,因为它们很容易被滥用.此外,它很容易实现.例如,commons-lang 有一个 MutableInt
.
No, Java doesn't have these built in. And that is for a reason. Using mutable types is dangerous, as they can easily be misused. Additionally, it is really easy to implement it. For example, commons-lang has a MutableInt
.
相关文章