title: Fail-safe injector for child modules. Optional bindings in google guice
body: <p>I have a child module called ChildPlugin and I inject classes from main module as follows:</p>
  
  <pre><code>public class ChildPlugin {
      private ExampleClass demo;
  
      @Inject
      public void setDemo(ExampleClass demo) { 
          this.demo = demo;
      }
  }
  </code></pre>
  
  <p>The problem is that I don't know whether the main module binds <code>ExampleClass</code> and if it's not Guice throws an exception when creating the injector. What I want to do is to make Guice pass <code>null</code> or <code>Optional.empty</code> if ExampleClass is not binded.</p>
  
  <p>I do not have access to the main module so I cannot change binder for <code>ExampleClass</code> to <code>OptionalBinder</code>, I tried <code>@Nullable</code> and <code>Optional&lt;ExampleClass&gt;</code> in <code>ChildPlugin.setDemo</code> method but it didn't work.</p>