Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Sign Up
Dashboard
backport175
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h3>Java 5 annotations</h3> <p>Java 5 annotations are standardized through the <table class="wysiwyg-macro" data-macro-name="unmigrated-inline-wiki-markup" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3VubWlncmF0ZWQtaW5saW5lLXdpa2ktbWFya3VwOmF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1CTE9DS30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>{link:JSR-175 specification|http://www.jcp.org/en/jsr/detail?id=175}{link}</pre></td></tr></table>. When you compile annotated source code the <code>javac</code> compiler will embed the annotations in the compiled class, and this information can then be read back using the reflection API.</p> <p>Annotations in Java 5 are first class citizen through the <code>@interface</code> keyword.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> // A Java 5 Annotation public @interface Asynchronous { int timeout() default 5; String label(); } // A Java 5 annotated method @Asynchronous(timeout=5, label="will run for a while") public Object someMethod() { ... } </pre></td></tr></table> <h3>backport175 annotations for Java 1.3/1.4</h3> <p><strong>backport175</strong> is an implementation of the <table class="wysiwyg-macro" data-macro-name="unmigrated-inline-wiki-markup" data-macro-parameters="atlassian-macro-output-type=BLOCK" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e3VubWlncmF0ZWQtaW5saW5lLXdpa2ktbWFya3VwOmF0bGFzc2lhbi1tYWNyby1vdXRwdXQtdHlwZT1CTE9DS30&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre>{link:JSR-175 specification|http://www.jcp.org/en/jsr/detail?id=175}{link}</pre></td></tr></table> for Java 1.3/1.4 which provides the same user experience as regular Java 5 annotations. </p> <p>Annotations are defined using a regular Java interface (hence providing strongly typed access to annotation values), and annotated source code appears in the form of doclet in the JavaDoc part.</p> <p>The backport175 compiler (available through command line or as an <a class="confluence-link" href="/display/175/Ant+task" data-linked-resource-id="18668" data-linked-resource-type="page" data-linked-resource-default-alias="Ant task" data-base-url="http://docs.codehaus.org">Ant task</a>) allows you to <a class="confluence-link" href="/display/175/Compiling+annotations" data-linked-resource-id="18662" data-linked-resource-type="page" data-linked-resource-default-alias="Compiling annotations" data-base-url="http://docs.codehaus.org">post-compile</a> your classes to embed the annotation information inside the class' bytecode. The annotations are bytecode compatible with regular Java 5 annotations and therefore can be treated the same by tools, regular Java reflection (on Java 5) etc.</p> <p>Note: it is advised to have a space between the annotation and its value as below though not mandatory.</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="java" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6amF2YX0&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> // A Java 1.3/1.4 Annotation with backport175 public interface Asynchronous { /** * Default value is supported through this specific annotation * * @org.codehaus.backport175.DefaultValue (5) */ int timeout(); String label(); } // A Java 1.3/1.4 annotated method /** * @Asynchronous (timeout=5, label="will run for a while") */ public Object someMethod() { ... } </pre></td></tr></table> <p>The annotations can then be accessed using the API in the <code>org.codehaus.backport175.reader.Annotations</code> class which allows to retrieve reflectively both regular Java 5 annotations and Java 1.3/1.4 annotations in a consistent way, allowing you to adopt annotation driven development even without Java 5, while having a simple migration path. For more information on how to access annotations, read <a class="confluence-link" href="/display/175/Reading+annotations" data-linked-resource-id="18674" data-linked-resource-type="page" data-linked-resource-default-alias="Reading annotations" data-base-url="http://docs.codehaus.org">this section</a>.</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced