Because that's not at all what Key.get(Class) is intended to do. Key is an
abstraction of an injectable type (either a raw Class or a generic
TypeLiteral), possibly with an associated binding annotation to
differentiate it from other Keys for the same type. Key.get(Class) is for
creating a Key representing a class with no binding annotation, which must
be equal to any other Key for the same class with no binding annotation. I
also think that what you're doing is something that should be needed only
very rarely in Guice applications, so it would be harmful to make it easier.

-- 
Colin


On Sat, Dec 31, 2011 at 4:31 PM, glenviewjeff <[email protected]>wrote:

> 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.
>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
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