class A:
import java.lang.reflect.Method; public class HelloWorld { public static void main(String[] args) { System.out.println("before test Dex"); HelloWorld hw = new HelloWorld(); hw.test(); System.out.println("after test Dex"); } public void test() { try { Class<?> cls = null; cls = Class.forName("Dex"); Object obj = cls.newInstance(); Method setFunc = cls.getDeclaredMethod("testDex"); setFunc.invoke(obj); } catch (Exception e) { e.printStackTrace(); } } }
Class B:
public class Dex { void testDex() { System.out.println("Dex123"); } }