Using int vs Integer

后端 未结 9 1466
抹茶落季
抹茶落季 2020-12-01 01:28

I came across a class using Integer variables to capture size to be used in a for loop. Is this good practice or should we use the int primitive data type?

I         


        
9条回答
  •  独厮守ぢ
    2020-12-01 01:49

    I normally use Integer because of purely OO. Performance of int is definitely far better than its object counterpart but it is noticeable only when you are looping millions time in the loop.

    IMHO, If performance is paramount importance in you application and you want to squeeze even single nano second then use int without any brain. But if OO and readability is main concerned then use Integer.

提交回复
热议问题