Here you can find the source of sizeOfPrimitive(Object object)
private static long sizeOfPrimitive(Object object)
//package com.java2s; //License from project: Open Source License public class Main { private static final Class<?> PRIMITIVE_CLASS[] = new Class[] { Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Character.class, Boolean.class }; private static final int PRIMITIVE_SIZE[] = new int[] { 1, 2, 4, 8, 4, 8, 1, 1 }; private static long sizeOfPrimitive(Object object) { if (object instanceof String) return ((String) object).getBytes().length; for (int i = 0; i < PRIMITIVE_CLASS.length; i++) if (object.getClass() == PRIMITIVE_CLASS[i]) return PRIMITIVE_SIZE[i]; return 0; }//w w w . j a v a2s.c o m }