Java Reflection Primitive isNumber(Class clazz)

Here you can find the source of isNumber(Class clazz)

Description

Indicate whether the clazz represents a number

License

Open Source License

Declaration

public static boolean isNumber(Class<?> clazz) 

Method Source Code


//package com.java2s;
// This package is part of the Spiralcraft project and is licensed under

import java.util.Map;
import java.util.HashMap;

public class Main {
    private static final Map<Class<?>, Class<?>> boxedEquivalentMap = new HashMap<Class<?>, Class<?>>();

    /**/* w  ww.  j  a v  a  2  s  . c  o  m*/
     * Indicate whether the clazz represents a number
     */
    public static boolean isNumber(Class<?> clazz) {
        return Number.class.isAssignableFrom(clazz) || Number.class.isAssignableFrom(boxedEquivalent(clazz));
    }

    /**
     * Return the boxed equivalent of the specified Class
     */
    public static Class<?> boxedEquivalent(Class<?> clazz) {
        return clazz.isPrimitive() ? boxedEquivalentMap.get(clazz) : clazz;
    }
}

Related

  1. isAJavaPrimitiveArrayClass(final Class type)
  2. isBoxed(Class boxedClass, Class primitiveClass)
  3. isExtPrimitive(Class clazz)
  4. isNumber(Class type)
  5. isNumber(Class type)
  6. isNumeric(Class operandClass)
  7. isNumericPrimitive(Class type)
  8. isNumericType(Class aNumberClass)
  9. isPrimitive(Class c)