準備調用的類
1
2
3
4
5
6
7
8
9
|
package ss; public class Use { public static Integer demo( String s ){ System.err.println(s+ "<<<<<<成功!" ); Integer ss= 1 ; return ss; } } |
執行調用的類
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
public class Ceshi { public static void main(String[] args) { try { String className = "ss.Use" ; Class<?> testClass = Class.forName(className); Method saddMethod2 = testClass.getMethod( "demo" , new Class[]{String. class }); String result=saddMethod2.invoke( null , new Object[]{ "測試反射" }).toString(); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } } |
以上這篇JAVA 反射 動態調用不同類的靜態方法(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持服務器之家。