Long vs Integer, long vs int, what to use and when?

前端 未结 7 763
醉梦人生
醉梦人生 2020-12-12 12:14

Sometimes I see API\'s using long or Long or int or Integer, and I can\'t figure how the decision is made for that?

7条回答
  •  醉话见心
    2020-12-12 12:54

    There are a couple of things you can't do with a primitive type:

    • Have a null value
    • synchronize on them
    • Use them as type parameter for a generic class, and related to that:
    • Pass them to an API that works with Objects

    Unless you need any of those, you should prefer primitive types, since they require less memory.

提交回复
热议问题