public class Sample {
private String data1;
private String data2;
public Sample() {
}
public Sample(String data1, String data2) {
this.data1 = data1;
this.data2 = data2;
}
public String data1() {
return data1;
}
}
// Class.forName("com.example.demo.Sample");
Class<Sample> clazz = Sample.class;
Field[] fields = clazz.getFields();
Annotation[] annotations = clazz.getAnnotations();
Method[] methods = clazz.getMethods();
Constructor<?>[] constructors = clazz.getConstructors();
Class<Sample> clazz = Sample.class;
Constructor<?> declaredConstructors = clazz.getDeclaredConstructors()[0];
Sample result =(Sample) declaredConstructors.newInstance();