All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pastdev.httpcomponents.factory.ValueOfValueFactory Maven / Gradle / Ivy

package com.pastdev.httpcomponents.factory;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class ValueOfValueFactory {
    @SuppressWarnings( "unchecked" )
    public static  T valueOf( String valueString, Class type ) {
        if ( type == String.class ) {
            return (T) valueString;
        }

        Method method;
        try {
            method = type.getDeclaredMethod( "valueOf", String.class );
            return (T) method.invoke( null, valueString );
        }
        catch ( NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
            throw new IllegalArgumentException( "Class " + type + " not supported", e );
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy