I have this simple class:

public class Ford implements Automobile {
        private int maxSpeed;

        public Ford(int speed) {
          System.out.println("Driving a Ford!");
                this.maxSpeed = speed;
        }

        @Override
        public int getMaxSpeed() {
                return maxSpeed;
        }

        public void printBrand(){
          System.out.println("Ford");

        }
}




I would like to inject this implementation into the CarShop below:




public class CarShop {
  private Automobile car;
        @Inject
        public CarShop(Automobile car) {
          this.car = car;
        }

        public void printBrand(){
          car.printBrand();
        }

        public void printMaxSpeed(){
          car.getMaxSpeed();
        }
}


In my Module I do:

public class MyCarModule extends AbstractModule {
        @Override
        protected void configure() {
            bind(Automobile.class).to(Ford.class);
        }
}


But how do I get the int passed to the constructor in my Ford
implementation?

I have looked at:

http://code.google.com/docreader/#p=google-guice&s=google-guice&t=FrequentlyAskedQuestions


but it seems pretty overkill to create a factory or an AssistedInject
to pass an int to a constructor.

Any ideas?
-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.


Reply via email to