还是举个例子给你吧
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- public class Fanshe
- {
- public static void main(String[] args)
- {
- try
- {
- String str="0123456789";
- Class<String> clas=String.class;
- Method me=clas.getDeclaredMethod("charAt", int.class);
- System.out.println(me.invoke(str,0));
- }
- catch (SecurityException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalArgumentException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
复制代码 |