private static Object valueOf ( final String value , final Class < ? > objectType ) { if ( objectType == Character . class ) { return value . charAt ( 0 ) ; } try { final Constructor < ? > constructor = objectType . getConstructor ( String . class ) ; return constructor . newInstance ( value ) ; } catch ( InstantiationException | InvocationTargetException | NoSuchMethodException | IllegalAccessException e ) { //this should never happen throw new RuntimeException ( //NOSONAR "Could not create instance of type " + objectType . getName ( ) + " from value " + value , e ) ; } }
Converts the given String value to a object type . The method assumes the object type has a constructor accepting a single String representation of the content .