1. 程式人生 > 實用技巧 >十:反射

十:反射

https://blog.csdn.net/qq_36226453/article/details/82790375

目前程式碼:

  

package Text;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class RunFanShe {
    
    private static final char[] Arcing = null
; public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, SecurityException, Exception { Class<?> forName = Class.forName("Text.Arcing"); Object newInstance = forName.getConstructor(String.class).newInstance("劉"); Method methods
= forName.getMethod("name", int.class); methods.invoke(newInstance, 20); } } class Arcing{ public String nameString = "bookfar"; public void name(int age) { System.out.println("my name is "+nameString+age); } public Arcing(String aString) {
// TODO Auto-generated constructor stub this.nameString = aString; System.out.println("you got it"); } }
View Code