jdk/src/java.base/share/classes/java/lang/annotation/Annotation.java
author chegar
Sun, 17 Aug 2014 15:54:13 +0100
changeset 25859 3317bb8137f4
parent 22080 jdk/src/share/classes/java/lang/annotation/Annotation.java@18a23ba7dd38
child 32033 bf24e33c7919
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 14342
diff changeset
     2
 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang.annotation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * The common interface extended by all annotation types.  Note that an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * interface that manually extends this one does <i>not</i> define
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * an annotation type.  Also note that this interface does not itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * define an annotation type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
9266
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
    34
 * More information about annotation types can be found in section 9.6 of
121fb370f179 7032960: API files in java.awt need to be updated for references to JVM Spec with editions/hyperlinks
jjh
parents: 5506
diff changeset
    35
 * <cite>The Java&trade; Language Specification</cite>.
1938
23526f724210 6327048: Enum javadoc could link to JLS
darcy
parents: 2
diff changeset
    36
 *
22080
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 18546
diff changeset
    37
 * The {@link java.lang.reflect.AnnotatedElement} interface discusses
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 18546
diff changeset
    38
 * compatibility concerns when evolving an annotation type from being
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 18546
diff changeset
    39
 * non-repeatable to being repeatable.
18a23ba7dd38 8023471: Add compatibility note to AnnotatedElement
darcy
parents: 18546
diff changeset
    40
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
public interface Annotation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Returns true if the specified object represents an annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * that is logically equivalent to this one.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * returns true if the specified object is an instance of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * annotation type as this instance, all of whose members are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * to the corresponding member of this annotation, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *    <li>Two corresponding primitive typed members whose values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *    unless their type is <tt>float</tt> or <tt>double</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *    <li>Two corresponding <tt>float</tt> members whose values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *    <li>Two corresponding <tt>double</tt> members whose values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *    definition is recursive for annotation typed members.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *    appropriate overloading of {@link java.util.Arrays#equals}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @return true if the specified object represents an annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *     that is logically equivalent to this one, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    boolean equals(Object obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Returns the hash code of this annotation, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * <p>The hash code of an annotation is the sum of the hash codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * of its members (including those with default values), as defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * The hash code of an annotation member is (127 times the hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * of the member-name as computed by {@link String#hashCode()}) XOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * the hash code of the member-value, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * <p>The hash code of a member-value depends on its type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *     {@link Long}, {@link Short}, or {@link Boolean}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * <li>The hash code of a string, enum, class, or annotation member-value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     I     <tt><i>v</i></tt> is computed as by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *     member values, this is a recursive definition.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <li>The hash code of an array member-value is computed by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *     the appropriate overloading of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *     on the value.  (There is one overloading for each primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *     type, and one for object reference types.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * @return the hash code of this annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Returns a string representation of this annotation.  The details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * of the representation are implementation-dependent, but the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * may be regarded as typical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return a string representation of this annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Returns the annotation type of this annotation.
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 14342
diff changeset
   133
     * @return the annotation type of this annotation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    Class<? extends Annotation> annotationType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
}