JDK 8 RFR, redux, for JDK-8005294 : Consider default methods for additions to AnnotatedElement

Joe Darcy joe.darcy at oracle.com
Wed Oct 30 16:41:09 UTC 2013


On 10/30/2013 12:52 AM, Peter Levart wrote:
>
> On 10/30/2013 02:57 AM, Joe Darcy wrote:
>> On 10/29/2013 06:37 PM, Joe Darcy wrote:
>>> Hi Joel,
>>>
>>> On 10/29/2013 09:20 AM, Joel Borggrén-Franck wrote:
>>>> Hi Joe, Peter,
>>>>
>>>> On 29 okt 2013, at 07:09, Joe Darcy <joe.darcy at oracle.com> wrote:
>>>>>
>>>

[snip]
>>
>> I retract my previous comments; I was confusing "annotationType" and 
>> "value()" in terms of where they are defined. This version of 
>> getDeclaredAnnotationsByType passes the battery of regression tests:
>>
>>     default <T extends Annotation> T[] 
>> getDeclaredAnnotationsByType(Class<T> annotationClass) {
>>         Objects.requireNonNull(annotationClass);
>>         return AnnotationSupport.
>> getDirectlyAndIndirectlyPresent(Arrays.stream(getDeclaredAnnotations()).
>> collect(Collectors.toMap(
>> (a -> a.annotationType()),
>> Function.identity(),
>> ((first,second) -> first),
>> () -> new LinkedHashMap<>() )),
>>                                             annotationClass);
>>     }
>
> Hi Joe,
>
> I suggest using method references where possible, which saves from 
> generating two (of three) synthetic methods in AnnotatedElement interface:
>
>                     Collectors.toMap(
>                         Annotation::annotationType,
>                         Function.identity(),
>                         (first, second) -> first,
>                         LinkedHashMap::new)
>
>

Hi Peter,

Good suggestion; I've made the recommended change:

     http://cr.openjdk.java.net/~darcy/8005294.7/

Thanks for the reviews,

-Joe




More information about the core-libs-dev mailing list