public static int sizeOf ( Class < ? > clz ) throws IllegalArgumentException { switch ( clz . getName ( ) ) { case "int" : return Integer . BYTES ; case "short" : return Short . BYTES ; case "long" : return Long . BYTES ; case "double" : return Double . BYTES ; case "float" : return Float . BYTES ; case "boolean" : return 1 ; case "char" : return Character . BYTES ; case "byte" : return 1 ; default : throw new IllegalArgumentException ( "Not a primitive type." ) ; } }
Get the size of a primitive type .