I have binding code all over that looks like this, so much so that I 
derived an AbstractModuleWithBindingHelpers from AbstractModule to help cut 
some of the code clutter.  

   private static final Key<Boolean> TRUE_KEY = Key.get(Boolean.class, 
randomAnnotation());
   private static final Key<Boolean> FALSE_KEY = Key.get(Boolean.class, 
randomAnnotation());

   protected static Named randomAnnotation() {
      return Names.named(UUID
            .randomUUID().toString());
   }

Why doesn't Key.get(Class<T> type) just do this by default?  I suppose this 
could help with debugging if someone accidentally requests a key on the 
same type more than once, but I would think that the value added in writing 
more concise code would be preferable. 

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/k2SOvuk58REJ.
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