Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.abc.test;
- import java.lang.reflect.InvocationTargetException;
- public class Main {
- public static void main(String[] args) {
- X x = new X();
- try {
- x.z("Hello, world");
- }
- catch(Exception e) {
- System.err.println(e);
- }
- }
- }
- class X {
- public void z(String text) throws IllegalAccessException, InstantiationException, ClassNotFoundException, InvocationTargetException, NoSuchMethodException {
- String a = "c.te";
- String b = "st.X";
- String c = "om.ab";
- Class clazz = Class.forName('c' + c + a + b);
- Object obj = clazz.newInstance();
- java.lang.reflect.Method method;
- method = obj.getClass().getMethod("y", text.getClass());
- method.invoke(obj, text);
- }
- public void y(String text) {
- System.out.println(text);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement