添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
体贴的柿子  ·  Unity ...·  1 年前    · 
正直的酸菜鱼  ·  Mysql ...·  1 年前    · 
独立的长颈鹿  ·  JR51699: ...·  1 年前    · 
public class ReflectDemo { public static void main(String[] args) throws Exception { ArrayList <String> list = new ArrayList<String> (); list.add( "enen" ); for (String str:list) { System.out.println(str); Class <? extends ArrayList> clas= list.getClass(); ArrayList <String> li=(ArrayList<String> ) clas.newInstance(); li.add( "san" ); for (String str:li) { System.out.println(str); Method[] metho = clas.getMethods(); for (Method met:metho) { System.out.println(met); Method meth =clas.getMethod("add",Object. class ); // 后边的.class 是add方法的参数的类型类 meth.invoke(li, "123" ); for (String str:li) { System.out.println(str); Class <?> c=Class.forName("com.swift.ADemo" ); ADemo a = (ADemo) c.newInstance(); a.fun(); Class cl = a.getClass(); ADemo b = (ADemo) cl.newInstance(); b.fun(); Method met =cl.getMethod("fun" ); met.invoke(b); Method[] m = c.getDeclaredMethods(); for (Method me:m) { System.out.println(me); Method method =c.getMethod("fun" ); method.invoke(a); class ADemo{ public void fun() { System.out.println( "A demo." );