Skip to content

Instantly share code, notes, and snippets.

@wjch
Created September 5, 2013 06:10
Show Gist options
  • Save wjch/6446593 to your computer and use it in GitHub Desktop.
Save wjch/6446593 to your computer and use it in GitHub Desktop.

1.果然是实践出真知:

public class Hello {

  
	public static  void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		Class<?> clazz = Class.forName("com.wjch.reflection.Person");	
		Person p = (Person) clazz.newInstance();
		Constructor<?>[]  cons = clazz.getConstructors();
		for(int i=0;i<cons.length;i++){
			System.out.println(cons[i]);
		}
	}
}

输出为:

public com.wjch.reflection.Person(java.lang.String,int)
public com.wjch.reflection.Person(int)
public com.wjch.reflection.Person(java.lang.String)
public com.wjch.reflection.Person()

输出结果与构造函数的顺序是相反的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment