Skip to content

Reflection request #6

@ghost

Description

You can add reflect and hide call,
like this:

import java.lang.reflect.Method;

public class Main {

	public static void main(String[] args) {
		unReflect("Main", "print", new Class<?>[] { String[].class }, new Object[] { new String[] { "Hello", "World" } }); // method call hide
	}

	static Object unReflect(String className, String methName, Class<?>[] argsType, Object[] methArgs) {
		try {
			Class<?> processClass = Class.forName(className);
			Object process = processClass.newInstance();
			Method aMethod = process.getClass().getDeclaredMethod(methName, argsType);
			if (!aMethod.isAccessible()) {
			aMethod.setAccessible(true);
			}
			return aMethod.invoke(process, methArgs);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	
	static void print(String[] str) {
		System.out.println(str[0] + " " + str[1]);
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions