public static Object instantiateWrapperObject ( Class < ? > type , Object objectToInvokeUpon , String valueToAssign ) { logger . entering ( new Object [ ] { type , objectToInvokeUpon , valueToAssign } ) ; validateParams ( type , objectToInvokeUpon , valueToAssign ) ; checkArgument ( ClassUtils . isPrimitiveWrapper ( type ) , type . getName ( ) + " is NOT a wrapper data type." ) ; try { Object objectToReturn = type . getConstructor ( new Class < ? > [ ] { String . class } ) . newInstance ( valueToAssign ) ; logger . exiting ( objectToInvokeUpon ) ; return objectToReturn ; } catch ( InstantiationException | NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) { throw new ReflectionException ( e ) ; } }
This helper method facilitates creation of Wrapper data type object and initialize it with the provided value .