Java Guice - how to bind integer value to my class/object?

I don't understand how can I simply bind any value when I bind a class. I always get this error:

No implementation for test.Triangle annotated with was bound.

I tried this:

Triangle class

public void setLength(@Named("triangle") int length) {
    this.length = length;

Configuration class

bind(Triangle.class).annotatedWith(Names.named("triangle")).toInstance(1); //this one just gives error that I can't do that.

How can I enter a value into it, so it would use setLength method with my chosen value?.. I read Guice documentation, but didn't find it. In Spring framework such things like these seemed much easier to do and understand (maybe it has better documentation, at least for me). Also if I missed in documentation where it shows this kind of thing you can link it too.



You don't want to bind Triangle to 1 - you want to bind Integer to 1. It might be better to use @Named("triangleLength") or even switch to a binding annotation (@IndicatesTriangleLength) to make the intention clear.

Need Your Help

ASP.NET MVC 2 - How do I pass a querystring back on response?


I need to pass a querystring back on response - so that via means of jQuery I can do something with it.