What is the difference between an int and an Integer in Java and C#?

前端 未结 26 1733
生来不讨喜
生来不讨喜 2020-11-22 12:00

I was reading More Joel on Software when I came across Joel Spolsky saying something about a particular type of programmer knowing the difference between an i

26条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 12:28

    One more thing that I don't see in previous answers: In Java the primitive wrappers classes like Integer, Double, Float, Boolean... and String are suposed to be invariant, so that when you pass an instance of those classes the invoked method couldn't alter your data in any way, in opositión with most of other classes, which internal data could be altered by its public methods. So that this classes only has 'getter' methods, no 'setters', besides the constructor.

    In a java program String literals are stored in a separate portion of heap memory, only a instance for literal, to save memory reusing those instances

提交回复
热议问题