Here you can find the source of sizeOf(Class> clz)
Parameter | Description |
---|---|
clz | a parameter |
Parameter | Description |
---|---|
IllegalArgumentException | If the class is not primitive type. |
public static int sizeOf(Class<?> clz) throws IllegalArgumentException
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w . j a va2s . com * Get the size of a primitive type. * * @param clz * @throws IllegalArgumentException If the class is not primitive type. * @return */ 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."); } } }