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

org.sfm.reflect.MethodHandleSetter Maven / Gradle / Ivy

package org.sfm.reflect;

import java.lang.invoke.MethodHandle;

public final class MethodHandleSetter implements Setter {

	private final MethodHandle method;
	private final Class type;
	
	@SuppressWarnings("unchecked")
	public MethodHandleSetter(final MethodHandle method) {
		this.method = method;
		this.type = (Class) method.type().parameterType(1);
	}

	public void set(final T target, final P value) throws Exception {
		try {
			method.invoke(target, value);
		} catch(Exception e) {
			throw e;
		} catch(Error e) {
			throw e;
		} catch(Throwable e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public Class getPropertyType() {
		return type;
	}
	
	public MethodHandle getMethodHandle() {
		return method;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy