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

com.g2forge.alexandria.reflection.object.implementations.JavaMethodReflection Maven / Gradle / Ivy

package com.g2forge.alexandria.reflection.object.implementations;

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

import com.g2forge.alexandria.generic.type.java.member.IJavaMethodType;
import com.g2forge.alexandria.java.core.error.RuntimeReflectionException;
import com.g2forge.alexandria.reflection.object.AJavaMemberReflection;
import com.g2forge.alexandria.reflection.object.IJavaMethodReflection;
import com.g2forge.alexandria.reflection.object.IJavaTypeReflection;
import com.g2forge.alexandria.reflection.object.HReflection;

public class JavaMethodReflection extends AJavaMemberReflectionimplements IJavaMethodReflection {
	public JavaMethodReflection(IJavaMethodType type) {
		super(type);
	}

	@Override
	public IJavaTypeReflection getReturnType() {
		return HReflection.toReflection(getType().getJavaMember().getGenericReturnType());
	}

	@Override
	public O invoke(T object, Object... args) {
		try {
			final Method method = type.getJavaMember();
			method.setAccessible(true);
			@SuppressWarnings("unchecked")
			final O retVal = (O) method.invoke(object, args);
			return retVal;
		} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) {
			throw new RuntimeReflectionException(exception);
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy