如下所示:
自动生成set、get、无惨构造、equals、canEqual、hashCode、toString方法
*/
@Data
public class Person {
private String name;
private int age;
public Person(String name){
this.name = name;
}
public Person(int age){
this.age = age;
}
public Person(String name,int age){...}
}
/**
- Created by hunt on 2017/6/27.
*/
public class NewInstanceTest {
public static void main(String[] args) {
ClasspersonClass = Person.class;
try {
Constructor<?> constructor = personClass.getConstructor(java.lang.String.class);
Person p = (Person) constructor.newInstance("hunt");
System.out.println(p);
} catch (Exception e) {
e.printStackTrace();
}
}
}