JDK 8 (initial) RFR for JDK-8005294 : Consider default methods for additions to AnnotatedElement
Joe Darcy
joe.darcy at oracle.com
Fri Oct 25 02:46:47 UTC 2013
Hi Joel,
On 10/24/2013 09:08 AM, Joel Borggrén-Franck wrote:
> Hi Joe,
>
> I think this a desirable change. Some design questions inline,
>
> Also please note the related work going on here: http://mail.openjdk.java.net/pipermail/core-libs-dev/2013-October/022590.html
>
> On 24 okt 2013, at 15:31, Joe Darcy <joe.darcy at oracle.com> wrote:
>
>> Hello,
>>
>> Please review my initial implementation changes for
>>
>> JDK-8005294 : Consider default methods for additions to AnnotatedElement
>> http://cr.openjdk.java.net/~darcy/8005294.0/
>>
>> (Specification aspects of the review are taking place over at
>> http://mail.openjdk.java.net/pipermail/enhanced-metadata-spec-discuss/2013-October/000279.html )
>>
> Here are some things that aren't clear to me:
>
> Why do you need to add AnnotatedElementSupport?
I wanted somewhere to put code to be shared among the two default
methods. (Private methods in interfaces are not allowed in Java SE 8
sources.) The need for the helper class may go away after the code is
refactored / corrected.
> We already have one version of getAssociatedAnnotations() (with a long history of being broken). Can we somehow unify this?
To a first approximation, code in default methods can do things like
call other methods defined in the interface or throw an exception.
Can getAssociatedAnnotations be expressed in such terms?
>
> Also, we did get into trouble when making isAnnotationPresent() a default? is it different for getDeclaredAnnotations()?
Copying the reply to this question sent over on enhanced-metadata-discuss:
"No; we don't have the same hazard here [making this methods defaults]
as with isAnnotationPresent. The issue we ran into with making
isAnnotationPresent a default method was that isAnnotationPresent was
part of the original AnnotatedElement interface defined way back in Java
SE 5. An implementation decision in javac did not expose the existence
of default methods to code being compiled under source levels less than
8. That is a pragmatic choice and usually gives the desired result, but
not in this case.
Making the new-in-Java-SE-8 methods in AnnotatedElement defaults follows
the generally recommended way to evolve interfaces when new methods are
added to them. "
> Will this work du to there being a concrete impl in all our concrete classes?
I did not really expect code in the JDK to use the logic in the default
methods. The default methods would be for implementations outside of the
JDK that didn't already have customized implementations of the new methods.
>
> Considering Class is the only type where getAnnotationsByType() is different from getDeclaredAnnotationsByType() isn't it cleaner to define getAnnotationsByType() in terms of getDeclaredAnnotatinosByType() and override in Class?
>
>
Hmm. I'll look into an approach along those lines. However, if possible,
I'd prefer to have both methods be logically stand along (even if they
share code).
Thanks for the comments,
-Joe
More information about the core-libs-dev
mailing list