Here you can find the source of unwrapPrimitive(final Class> clazz)
Parameter | Description |
---|---|
clazz | The Class to unwrap |
public static Class<?> unwrapPrimitive(final Class<?> clazz)
//package com.java2s; /*/*from ww w. ja v a2 s . c om*/ * Copyright 2012 Robert Philipp * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.HashMap; import java.util.Map; public class Main { private static Map<Class<?>, Class<?>> UNWRAP_MAP = new HashMap<>(); /** * If the specified {@link Class} is a wrapped primitive, then this function will return the primitive * version. For example, if the specified {@link Class} is {@code Integer.class} this method will return * {@code int.class} or equivalently, or {@code Integer.TYPE} * @param clazz The {@link Class} to unwrap * @return The specified {@link Class} or the primitive version of the {@link Class} if it is a wrapped primitive */ public static Class<?> unwrapPrimitive(final Class<?> clazz) { if (UNWRAP_MAP.containsKey(clazz)) { return UNWRAP_MAP.get(clazz); } else { return clazz; } } }