Here you can find the source of primitiveToWrapper(Class in)
Parameter | Description |
---|---|
in | non-null class |
public static Class primitiveToWrapper(Class in)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from w ww . j av a2s . c o m*/ * { field * * @name gWrapperClasses * @function list of java wrapper classes corresponding to primative types * } */ protected static final Class gWrapperClasses[] = { Integer.class, Float.class, Boolean.class, Double.class, Byte.class, Character.class, Integer.class, Long.class }; /** * { field * * @name gPrimitiveClasses * @function list of java wrapper classes corresponding to primative types * } */ protected static final Class gPrimitiveClasses[] = { Integer.TYPE, Float.TYPE, Boolean.TYPE, Double.TYPE, Byte.TYPE, Character.TYPE, Integer.TYPE, Long.TYPE }; protected static Map gPrimitiveClassToWrapper; protected static Map gWrapperToPrimitiveClass; /** * convert the input class to a wrapper class * returns in if the argument is not primitive * * @param in non-null class * @return non-null class guaranteed not to be primitive */ public static Class primitiveToWrapper(Class in) { if (!in.isPrimitive()) return (in); if (gPrimitiveClassToWrapper == null) buildWrapperMapping(); return ((Class) gPrimitiveClassToWrapper.get(in)); } /** * build mappings primitive to Wrapper */ protected static synchronized void buildWrapperMapping() { if (gPrimitiveClassToWrapper != null) return; // already done Map TheMap = new HashMap(); Map TheMap2 = new HashMap(); for (int i = 0; i < gPrimitiveClasses.length; i++) { TheMap.put(gPrimitiveClasses[i], gWrapperClasses[i]); TheMap2.put(gWrapperClasses[i], gPrimitiveClasses[i]); } gWrapperToPrimitiveClass = TheMap2; gPrimitiveClassToWrapper = TheMap; } }