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

前端 未结 7 760
醉梦人生
醉梦人生 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:47

    a) object Class "Long" versus primitive type "long". (At least in Java)

    b) There are different (even unclear) memory-sizes of the primitive types:

    Java - all clear: https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

    • byte, char .. 1B .. 8b
    • short int .. 2B .. 16b
    • int .. .. .. .. 4B .. 32b
    • long int .. 8B .. 64b

    C .. just mess: https://en.wikipedia.org/wiki/C_data_types

    • short .. .. 16b
    • int .. .. .. 16b ... wtf?!?!
    • long .. .. 32b
    • long long .. 64b .. mess! :-/

提交回复
热议问题