// TODO Auto-generated method stub
System.out.println("[消息]:发送一个云消息");
private Factory(){} //没有产生实例化对象,所以构造对象私有化
@SuppressWarnings("unchecked")
* @param clazz 描述的是一个接口的类型
* @return 如果子类存在则返回接口实例化对象
public static <T> T getInstance(String className, Class<T> clazz){
instance = (T)Class.forName(className).getDeclaredConstructor().newInstance();
public static void main(String[] args) throws Exception {
IMessage msg = Factory.getInstance("cn.cccc.demo.CloudMessage", IMessage.class);
IService ser = Factory.getInstance("cn.cccc.demo.HouseService", IService.class);