Are Java wrapper classes really immutable?

后端 未结 6 1680
借酒劲吻你
借酒劲吻你 2020-12-16 12:16

Java Wrapper classes are supposed to be immutable. This means that once an object is being created, e.g.,

Integer i = new Integer(5);

its

6条回答
  •  天涯浪人
    2020-12-16 12:51

    Immutable means that the object state cannot be changed. In your case you haven't changed the object new Integer(5), but you have changed the reference i to point to another object. Hope it is clear:)

提交回复
热议问题