public class Factory { public static Person staticCreate(){ Person p = new Person(); p.name="staticCreate"; return p; } public Person instanceCreate(){ Person p = new Person(); p.name="instanceCreate"; return p; } } public static void…
public class CarFactory { //非静态方法 public Car createCar(){ Car car = new Car(); car.setBrand("BMW"); return car; } //静态方法 public static Car createStaticCar(){ Car car = new Car(); return car; } } 1.对于非静态方法createCar的注入方式: 非静态方法:必须实例化工厂类(factory-be…