类一
public class AA { // 相加 public int sum(int a, int b) { System.out.println("反射小练习......2"); return a + b; } // 重写相加 public int sum(int a, int b, int c) { return a + b + c; }}
类二
import java.lang.reflect.Method;import org.testng.annotations.Test;public class TestAA { @Test public void testaa() throws Exception { // 获取到AA字节码在内存中对象 Class clazz = AA.class; // 获取AA字节码对象上名称为sum的方法,参数有2个参数 Method md = clazz.getMethod("sum", int.class, int.class); // 执行md方法 md.invoke(new AA(), 123, 4); }}
[TestNG] Running:
反射小练习......2
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦