private Object createEmptyWrapper ( Class < ? > type ) { if ( Number . class . isAssignableFrom ( type ) ) { Method method = ReflectionUtil . getDeclaredMethodBySignature ( type , "valueOf" , String . class ) ; if ( method != null && method . getReturnType ( ) == type ) { return ReflectionUtil . invokeMethod ( type , method , "0" ) ; } if ( type == BigInteger . class ) return BigInteger . ZERO ; if ( type == BigDecimal . class ) return BigDecimal . ZERO ; return null ; } if ( type == Boolean . class ) return false ; if ( type == Character . class ) return ( char ) 0 ; // better return something else? return null ; }
also handles some numeric types which aren t primitive wrapper types