public static Object convertPrimitive ( Object object ) { if ( object == null ) { return object ; } Class < ? > clazz = object . getClass ( ) ; if ( clazz . isPrimitive ( ) ) { if ( boolean . class . equals ( clazz ) ) { Boolean b = ( Boolean ) object ; return b ; } if ( byte . class . equals ( clazz ) ) { Byte b = ( Byte ) object ; return b ; } if ( char . class . equals ( clazz ) ) { Character c = ( Character ) object ; return c ; } if ( short . class . equals ( clazz ) ) { Short s = ( Short ) object ; return s ; } if ( int . class . equals ( clazz ) ) { Integer i = ( Integer ) object ; return i ; } if ( long . class . equals ( clazz ) ) { Long l = ( Long ) object ; return l ; } if ( float . class . equals ( clazz ) ) { Float f = ( Float ) object ; return f ; } if ( double . class . equals ( clazz ) ) { Double d = ( Double ) object ; return d ; } throw new IllegalArgumentException ( "Unknown primitive type'" + clazz ) ; } return object ; }
Convert a primitive object to its Class object