Tuesday, September 2, 2014

Guice Injection + Anonymous inner classes ??








Hi Java experts,








I have been using Guice for a while but just now run into a need to use anonymous inner classes. In the example below Car and its dependencies do not get injected resulted in NPE on consecutive calls. How can this be changed to work properly? Do I need to add extra binding?








public class Truck {







@Inject







public Truck(Engine engine) {







this.engine = engine;







}








public Car getCar() {







return new Car() {







@Override







public void drive() {







....







}







};







}







}








thanks!















No comments:

Post a Comment