Movatterモバイル変換


[0]ホーム

URL:


JEP 120: Repeating Annotations

AuthorJoseph D. Darcy
OwnerAlex Buckley
TypeFeature
ScopeSE
StatusClosed / Delivered
Release8
Componentspecification / language
JSRs269 MR,337
Discussionenhanced dash metadata dash spec dash discuss at openjdk dot java dot net
EffortS
DurationM
DependsJEP 104: Type Annotations
Endorsed byBrian Goetz
Created2011/10/17 20:00
Updated2015/02/13 19:40
Issue8046110

Summary

Change the Java programming language to allow multiple applicationof annotations with the same type to a single program element.

Goals

Improve the readability of source code which logically appliesmultiple instances of the same annotation type to a given programelement.

Motivation

Frequently-used idioms of programming with annotations in EE andelsewhere awkwardly use a container annotation just to simulate theability to apply multiple annotations. Building in support forrepeated annotations will improve the readability of source code.

Description

The basic approach to implement the language feature is to desugarrepeated annotations of a base type into a single containerannotation; the container annotation has avalues method whichreturns an array of the base annotation type. For repeatedannotations to be enabled for a particular annotation type, thedeclaration of the base annotation type will need to include a newmeta-annotation, say@ContainerAnnotation, to declare which otherannotation type should be used as a container. Warnings and errorsshould be issued if the container is not suitability compatible withthe base annotation, including problematic differences in retentionpolicy or target.

Open design issues include whether or not multiple levels ofcompiler-generated containers will be supported. For example, should

@A(1)@A(2)@AContainer@AContainerContainerfoo();

be treated as logically equivalent to

@AContainerContainer(@AContainer({@A(1), @A2}), @AContainer)foo();

or a compilation error after one level of nesting to

@AContainer({@A(1), @A(2)})@AContainer@AContainerContainerfoo();

At a libraries level, the implementations of the reflective APIs inthe platform, including core reflection andjavax.lang.model, willneed to be updated to handle the repeated annotation information. Forexample, theAnnotatedElement.getAnnotation(BaseAnnotation.class)method will be redefined to look for in a container annotation if thebase annotation is not directly present. One or more methods to queryfor the presence of absence of annotations may be added to theAnnotatedElement interface. If multiple levels of compiler-generatednesting is supported, the library changes will be more extensive.

Testing

As with all language changes, the corresponding compiler JCK testswill need to be updated.

Risks and Assumptions

One risk is the possibility of currently unforeseen interactionsbetween this language feature and existing library semantics orbetween this language feature other language features present in JavaSE 8. In particular, the interaction, if any, between repeatedannotations and annotations on types will need to be defined.

An assumption is that existing EE annotation types which use themanual container annotation pattern will migrate to use the repeatingannotations pattern and thereby validate the feature through usage.

If the various Java IDEs do not support this language change duringdevelopment, experimentation with the feature and validation of itsdesign will be slowed.

Dependences

The interaction between repeating annotations andJEP 104: Annotations on Java Types, if any, needs to be defined.

Impact

OpenJDK logo
Installing
Contributing
Sponsoring
Developers' Guide
Vulnerabilities
JDK GA/EA Builds
Mailing lists
Wiki ·IRC
Mastodon
Bluesky
Bylaws ·Census
Legal
Workshop
JEP Process
Source code
GitHub
Mercurial
Tools
Git
jtreg harness
Groups
(overview)
Adoption
Build
Client Libraries
Compatibility & Specification Review
Compiler
Conformance
Core Libraries
Governing Board
HotSpot
IDE Tooling & Support
Internationalization
JMX
Members
Networking
Porters
Quality
Security
Serviceability
Vulnerability
Web
Projects
(overview,archive)
Amber
Babylon
CRaC
Code Tools
Coin
Common VM Interface
Developers' Guide
Device I/O
Duke
Galahad
Graal
IcedTea
JDK 8 Updates
JDK 9
JDK (…,24,25,26)
JDK Updates
JMC
Jigsaw
Kona
Lanai
Leyden
Lilliput
Locale Enhancement
Loom
Memory Model Update
Metropolis
Multi-Language VM
Nashorn
New I/O
OpenJFX
Panama
Penrose
Port: AArch32
Port: AArch64
Port: BSD
Port: Haiku
Port: Mac OS X
Port: MIPS
Port: Mobile
Port: PowerPC/AIX
Port: RISC-V
Port: s390x
SCTP
Shenandoah
Skara
Sumatra
Tsan
Valhalla
Verona
VisualVM
Wakefield
Zero
ZGC
Oracle logo
© 2025 Oracle Corporation and/or its affiliates
Terms of Use · License:GPLv2 ·Privacy ·Trademarks

[8]ページ先頭

©2009-2025 Movatter.jp