After some test I can answer myself. It’s bad because equals() is broken (2 annotations
created with this code won’t be equals). And it works probably because all the equals call
done in Weld are made from the inner Annotation not from user instance…
Also Annotation is not a functional interface.
Antoine
Le 15 sept. 2016 à 11:03, Martin Kouba <mkouba(a)redhat.com> a
écrit :
Dne 15.9.2016 v 10:48 Antoine Sabot-Durand napsal(a):
>
>> Le 15 sept. 2016 à 10:26, Martin Kouba <mkouba(a)redhat.com> a écrit :
>>
>> Dne 15.9.2016 v 10:15 Antoine Sabot-Durand napsal(a):
>>> Just a naive remark regarding Instance of annotations without members. I
already used a lambda to have such an instance:
>>>
>>> BeanManager.getBeans(MyBean.class, () -> MyQualifier.class)
>>
>> What is this cryptic unclear lambda thing doing actually? I know it compiles but
I don't understand…
>
> It compiles and works every the time I used it. From my understanding it’s a short
cut for
>
> BeanManager.getBeans(MyBean.class, new Annotation() {
> @Override
> public Class<? extends Annotation> annotationType() {
> return MyQualifier.class;
> }
> })
>
> Which by the way also works. From your answer I guess it’s a bad solution ;), but I’d
be happy to know why and what is the side effect makes it work.
I don't say it's a bad solution, but it's not obvious and I consider similar
things a bad practice, especially if we don't understand why it works ;-)
>
> Thanks,
>
> Antoine
>
>>
>>>
>>> I’m not sure there are no problem by using this short cut, but it is quite
convenient.
>>>
>>> Antoine
>>>
>>>
>>>> Le 12 sept. 2016 à 12:28, arjan tijms <arjan.tijms(a)gmail.com> a
écrit :
>>>>
>>>> Hi,
>>>>
>>>> Wouldn't it be convenient as the CDI API that now requires an
Annotation instance in various APIs, would also accept the class type of that Annotation?
>>>>
>>>> E.g. in BeanManager there's this method:
>>>>
>>>> Set<Bean<?>> getBeans(Type beanType, Annotation...
qualifiers)
>>>>
>>>> This not rarely requires one to create an AnnotationLiteral, which is not
specifically difficult but a tad verbose. For qualifiers that have no (binding)
attributes, a simple Class would be much easier to use.
>>>>
>>>> Thoughts?
>>>>
>>>> Kind regards,
>>>> Arjan Tijms
>>>> _______________________________________________
>>>> cdi-dev mailing list
>>>> cdi-dev(a)lists.jboss.org
>>>>
https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>>
>>>> Note that for all code provided on this list, the provider licenses the
code under the Apache License, Version 2
(
http://www.apache.org/licenses/LICENSE-2.0.html). For all other ideas provided on this
list, the provider waives all patent and other intellectual property rights inherent in
such information.
>>>
>>>
>>> _______________________________________________
>>> cdi-dev mailing list
>>> cdi-dev(a)lists.jboss.org
>>>
https://lists.jboss.org/mailman/listinfo/cdi-dev
>>>
>>> Note that for all code provided on this list, the provider licenses the code
under the Apache License, Version 2 (
http://www.apache.org/licenses/LICENSE-2.0.html). For
all other ideas provided on this list, the provider waives all patent and other
intellectual property rights inherent in such information.
>>>
>
--
Martin Kouba
Software Engineer
Red Hat, Czech Republic