Why does post-increment work on wrapper classes

前端 未结 5 669
南笙
南笙 2020-12-11 15:53

I was doing a review of some code and came across an instance of someone post-incrementing a member variable that was a wrapper class around Integer. I tried it myself and

5条回答
  •  悲&欢浪女
    2020-12-11 16:16

    As of Java 1.5, Java performs auto-unboxing to convert "wrapper types" such as Integer to the corresponding primitive type int when necessary. Then the increment operator can work on the resulting int.

提交回复
热议问题