interface car{
void driver();
}
interface yxl{
void love();
}
class yb implements yxl{
@Override
public void love() {
System.out.println("love");
}
}
class BMW implements car{
@Override
public void driver() {
System.out.println("Driver BMW");
}
}
class Factory {
public static void main(String[] args)
{
car car=MyFactory.getInstance("BMW");
car.driver();
yxl myxhh=MyFactory.getInstance("yb");
myxhh.love();
}
}
class MyFactory<T>{
private MyFactory(){}
@SuppressWarnings("unchecked")
public static <T> T getInstance(String className){
T t=null;
try {
t=(T)Class.forName(className).newInstance();
} catch (Exception e) {
e.printStackTrace();
}
return t;
}
}