Comment #8 on issue 771 by [email protected]:
Annotations.isAllDefaultMethods returns false for method less interfaces.
http://code.google.com/p/google-guice/issues/detail?id=771
So, the problem is that any piece of code has to drag around this
dichtonomy between "Annotation" (IAW Names.named() and friends) and Class<?
extends Annotation> (if using a marker annotation). There is no good way to
pull them together so that subsequent code can use an "XXX" to represent
both. Key is really close to it but when handing a key around, there are
still two methods to check, whether it was created from an Annotation or a
Class<? extends Annotation>.
The code example above does something very different (and you will see why
your ofType comment does not apply):
- I have a key that represents a type and either an Annotation or a Class<?
extends Annotation>
- I want to create a new key for a different class that has the same
Annotation or Class<? extends Annotation> (the use case is that I bind an
object with those and want to inject dependencies that were bound the same
way into the objects). To create this key, I now need to inspect the Key
passed in and figure out whether it was created from an Annotation (then
getAnnotation() returns non-null) or an AnnotationType (then
getAnnotationType() returns non null). This would be so much simpler if for
any AnnotationType (Class<? extends Annotation>) used as a marker
annotation, the getAnnotation() would actually return something (a fake
implementation of the Marker annotation passed in).
Is it a bug? Well, as you mention that this is intentional, maybe not. Is
it a bad API? Probably because it forces me to do this crab walk of
checking left / checking right all the time. And the irony of it all is
that I can actually fix that trivially in my code by using
public @interface Bar {
String workaroundGuiceImplementationLimitation() default "";
}
as a marker interface and then only look at clazzKey.getAnnotation() above.
(In my internal code, the method has a different name).
And given that the proposed change would actually align with the current
behavior (instead of creating an instance only if 1..n methods with default
present, this now creates an instance when 0..n methods with default are
present).
I simply think that right now, the code is just not doing the right thing.
So it is a bug. IMHO.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice-dev.
For more options, visit https://groups.google.com/groups/opt_out.