Is there any sizeof-like method in Java?

后端 未结 15 1058
暗喜
暗喜 2020-11-27 15:03

Is there any built-in method in Java to find the size of any datatype? Is there any way to find size?

15条回答
  •  一生所求
    2020-11-27 15:41

    The Java Native Access library is typically used for calling native shared libraries from Java. Within this library there exist methods for determining the size of Java objects:

    The getNativeSize(Class cls) method and its overloads will provide the size for most classes.

    Alternatively, if your classes inherit from JNA's Structure class the calculateSize(boolean force) method will be available.

提交回复
热议问题