SHARE
TWEET

Untitled

a guest Feb 11th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.google.inject.AbstractModule;
  2. import com.google.inject.Guice;
  3. import com.google.inject.Inject;
  4. import com.google.inject.Injector;
  5.  
  6. public class GuiceDemo
  7. {
  8.     public static void main(String[] args)
  9.     {
  10.         new GuiceDemo().run();
  11.     }
  12.  
  13.     public void run()
  14.     {
  15.         Injector injector = Guice.createInjector(new EmptyModule());
  16.         DemoInstance demoInstance = injector.getInstance(DemoInstance.class);
  17.         assert(demoInstance.demoUnbound == null);
  18.     }
  19.  
  20.     public static class EmptyModule extends AbstractModule
  21.     {
  22.         @Override
  23.         protected void configure()
  24.         {
  25.         }
  26.     }
  27.  
  28.     public static class DemoInstance
  29.     {
  30.         public final DemoUnbound demoUnbound;
  31.  
  32.         @Inject
  33.         public DemoInstance(DemoUnbound demoUnbound)
  34.         {
  35.             this.demoUnbound = demoUnbound;
  36.         }
  37.     }
  38.  
  39.     public static class DemoUnbound
  40.     {
  41.     }
  42. }
  43.    
  44. public class GuiceDemo
  45. {
  46.     public static void main(String[] args)
  47.     {
  48.         new GuiceDemo().run();
  49.     }
  50.  
  51.     public void run()
  52.     {
  53.         Injector injector = Guice.createInjector(new EmptyModule());
  54.         DemoInstance demoInstance = injector.getInstance(DemoInstance.class);
  55.         assert(demoInstance.demoUnbound == null);
  56.     }
  57.  
  58.     public static class EmptyModule extends AbstractModule
  59.     {
  60.         @Override
  61.         protected void configure()
  62.         {
  63.         }
  64.     }
  65.  
  66.     public static class DemoInstance
  67.     {
  68.         public final DemoUnbound demoUnbound;
  69.  
  70.         @Inject
  71.         public DemoInstance(DemoUnbound demoUnbound)
  72.         {
  73.             this.demoUnbound = demoUnbound;
  74.         }
  75.     }
  76.  
  77.     public interface DemoUnbound
  78.     {
  79.     }
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top