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

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

The newest version!
package com.pastdev.httpcomponents.factory;

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

public class ValueOfValueFactory {
    public static  T valueOf( String valueString, Class type ) {
        if ( valueString == null || type == String.class ) {
            return type.cast( valueString );
        }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy