Let’s say you want to call MyClass.myMethod(int x);
Method m = MyClass.class.getDeclaredMethod("myMethod", Integer.TYPE);
m.setAccessible(true); //if security settings allow this
Object o = m.invoke(null, 23); //use null if the method is static
More Related Contents:
- How do I invoke a Java method when given the method name as a string?
- What could cause java.lang.reflect.InvocationTargetException?
- Can you find all classes in a package using reflection?
- How do I programmatically compile and instantiate a Java class?
- Modify a class definition’s annotation string parameter at runtime
- Gson TypeToken with dynamic ArrayList item type
- Java Reflection Performance
- Can I obtain method parameter name using Java reflection?
- How to solve InaccessibleObjectException (“Unable to make {member} accessible: module {A} does not ‘opens {package}’ to {B}”) on Java 9?
- How do I read all classes from a Java package in the classpath?
- Get all of the Classes in the Classpath
- What is the difference between a.getClass() and A.class in Java?
- How to convert a Java object (bean) to key-value pairs (and vice versa)?
- Copy all values from fields in one class to another through reflection
- Getting Class type from String
- Getting value of public static final field/property of a class in Java via reflection
- How to get Method Parameter names in Java 8 using reflection?
- Changing private final fields via reflection
- Accessing Java static final variable value through reflection
- Check if a Class Object is subclass of another Class Object in Java
- Difference between Loading a class using ClassLoader and Class.forName
- Java Reflection: Why is it so slow?
- Find out which classes of a given API are used
- Disable Java reflection for the current thread
- How does the event dispatch thread work?
- What’s the best way to get a Class object for an array type?
- Java getMethod with subclass parameter
- Check type of primitive field
- Cast via reflection and use of Class.cast() [duplicate]
- How to watch a variable for changes