Here you can find the source of resolvePrimitiveIfNecessary(Class> clazz)
Parameter | Description |
---|---|
clazz | the class to check |
public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz)
//package com.java2s; import java.util.HashMap; import java.util.Map; public class Main { /**/*from w ww . j a va 2 s. c om*/ * Map with primitive type as key and corresponding wrapper * type as value, for example: int.class -> Integer.class. */ private static final Map<Class<?>, Class<?>> primitiveTypeToWrapperMap = new HashMap<Class<?>, Class<?>>(8); /** * Resolve the given class if it is a primitive class, * returning the corresponding primitive wrapper type instead. * @param clazz the class to check * @return the original class, or a primitive wrapper for the original primitive type */ public static Class<?> resolvePrimitiveIfNecessary(Class<?> clazz) { if (clazz == null) { throw new IllegalArgumentException("Class must not be null"); } return (clazz.isPrimitive() && clazz != void.class ? primitiveTypeToWrapperMap.get(clazz) : clazz); } }