Are Java wrapper classes really immutable?

后端 未结 6 1685
借酒劲吻你
借酒劲吻你 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:32

    Integer i = new Integer(5);
    i++;                         // i  will become 6
    

    where i++ is the same with i = new Integer( i.intValue() + 1);

提交回复
热议问题