title: How do I make an optional binding in Guice?
body: <p>Here is my client:</p>
  
  <pre><code>class Client {
      @Inject(optional=true) Service service;
  }
  </code></pre>
  
  <p>Sometimes that Service isn't needed, and we know that information when the JVM starts (i.e before the binder is run).
  How do I make the binding optional? If I don't specify a binding at all it tries to new the Service (and fails because there is no zero-argument constructor: "<i>Error while injecting at package.Client.service(Service.java:40): Could not find a suitable constructor in package.Service.</i>"), and I can't do:</p>
  
  <pre><code>binder.bind(Service.class).toInstance(null);
  </code></pre>
  
  <p>because Guice seems to disallow nulls. Any ideas?</p>