jdk/src/share/classes/java/lang/annotation/Annotation.java
author jfranck
Mon, 30 Sep 2013 11:18:18 +0200
changeset 20481 2735b307d256
parent 18546 862067c6481c
child 22080 18a23ba7dd38
permissions -rw-r--r--
8007072: Update Core Reflection for Type Annotations to match latest spec 8022324: j.l.Class.getAnnotatedInterfaces() for array type returns wrong value 8024915: j.l.r.Executable.getAnnotatedReceiverType() should return null for static methods Summary: Update javadoc and implementation of reflection for type annotations to match latest spec Reviewed-by: darcy
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
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @since   1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public interface Annotation {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Returns true if the specified object represents an annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * that is logically equivalent to this one.  In other words,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * returns true if the specified object is an instance of the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * annotation type as this instance, all of whose members are equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * to the corresponding member of this annotation, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *    <li>Two corresponding primitive typed members whose values are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *    unless their type is <tt>float</tt> or <tt>double</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *    <li>Two corresponding <tt>float</tt> members whose values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *    <li>Two corresponding <tt>double</tt> members whose values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *    definition is recursive for annotation typed members.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *    appropriate overloading of {@link java.util.Arrays#equals}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @return true if the specified object represents an annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *     that is logically equivalent to this one, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    boolean equals(Object obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Returns the hash code of this annotation, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <p>The hash code of an annotation is the sum of the hash codes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * of its members (including those with default values), as defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * The hash code of an annotation member is (127 times the hash code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * of the member-name as computed by {@link String#hashCode()}) XOR
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * the hash code of the member-value, as defined below:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <p>The hash code of a member-value depends on its type:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *     {@link Long}, {@link Short}, or {@link Boolean}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <li>The hash code of a string, enum, class, or annotation member-value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     I     <tt><i>v</i></tt> is computed as by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *     member values, this is a recursive definition.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <li>The hash code of an array member-value is computed by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *     the appropriate overloading of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *     on the value.  (There is one overloading for each primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *     type, and one for object reference types.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return the hash code of this annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    int hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Returns a string representation of this annotation.  The details
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * of the representation are implementation-dependent, but the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * may be regarded as typical:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @return a string representation of this annotation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    String toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Returns the annotation type of this annotation.
18546
862067c6481c 8017550: Fix doclint issues in java.lang and subpackages
darcy
parents: 14342
diff changeset
   129
     * @return the annotation type of this annotation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    Class<? extends Annotation> annotationType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
}