1.反射对象
1.1 通过反射构建无参数对象
public class ReflectServiceImpl {
public void sayHello(String name){
System.err.println("Hello "+name);
}
public ReflectServiceImpl getInstance(){
ReflectServiceImpl object = null;
try {
//给类加载器注册一个类ReflectServiceImpl的全限定类名,然后通过newInstance办法初始化一个类对象
object = (ReflectServiceImpl)Class.forName("com.lean.ssm.chapter2.ReflectServiceImpl").newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return object;
}
}
public class ReflectService