可以通過基礎類型對應的包裝類獲取基礎類型的大小,如char,可以查看Character類:
/**
* The number of bits used to represent a {@code char} value in unsigned
* binary form, constant {@code 16}.
*
* @since 1.5
*/
public static final int SIZE = 16;
/**
* The number of bytes used to represent a {@code char} value in unsigned
* binary form.
*
* @since 1.8
*/
public static final int BYTES = SIZE / Byte.SIZE;
可知Character佔用2字節,16位.