rt/emul/compact/src/main/java/java/lang/annotation/Annotation.java
author Jaroslav Tulach <jtulach@netbeans.org>
Mon, 21 Oct 2013 14:38:36 +0200
branchjdk7-b147
changeset 1379 b5f9d743a090
permissions -rw-r--r--
Adding annotation classes into the emulation layer
jtulach@1379
     1
/*
jtulach@1379
     2
 * Copyright (c) 2003, 2009, Oracle and/or its affiliates. All rights reserved.
jtulach@1379
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1379
     4
 *
jtulach@1379
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@1379
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@1379
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@1379
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@1379
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@1379
    10
 *
jtulach@1379
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1379
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1379
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@1379
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1379
    15
 * accompanied this code).
jtulach@1379
    16
 *
jtulach@1379
    17
 * You should have received a copy of the GNU General Public License version
jtulach@1379
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1379
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1379
    20
 *
jtulach@1379
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1379
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@1379
    23
 * questions.
jtulach@1379
    24
 */
jtulach@1379
    25
jtulach@1379
    26
package java.lang.annotation;
jtulach@1379
    27
jtulach@1379
    28
/**
jtulach@1379
    29
 * The common interface extended by all annotation types.  Note that an
jtulach@1379
    30
 * interface that manually extends this one does <i>not</i> define
jtulach@1379
    31
 * an annotation type.  Also note that this interface does not itself
jtulach@1379
    32
 * define an annotation type.
jtulach@1379
    33
 *
jtulach@1379
    34
 * More information about annotation types can be found in section 9.6 of
jtulach@1379
    35
 * <cite>The Java&trade; Language Specification</cite>.
jtulach@1379
    36
 *
jtulach@1379
    37
 * @author  Josh Bloch
jtulach@1379
    38
 * @since   1.5
jtulach@1379
    39
 */
jtulach@1379
    40
public interface Annotation {
jtulach@1379
    41
    /**
jtulach@1379
    42
     * Returns true if the specified object represents an annotation
jtulach@1379
    43
     * that is logically equivalent to this one.  In other words,
jtulach@1379
    44
     * returns true if the specified object is an instance of the same
jtulach@1379
    45
     * annotation type as this instance, all of whose members are equal
jtulach@1379
    46
     * to the corresponding member of this annotation, as defined below:
jtulach@1379
    47
     * <ul>
jtulach@1379
    48
     *    <li>Two corresponding primitive typed members whose values are
jtulach@1379
    49
     *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
jtulach@1379
    50
     *    unless their type is <tt>float</tt> or <tt>double</tt>.
jtulach@1379
    51
     *
jtulach@1379
    52
     *    <li>Two corresponding <tt>float</tt> members whose values
jtulach@1379
    53
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
jtulach@1379
    54
     *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
jtulach@1379
    55
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
jtulach@1379
    56
     *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
jtulach@1379
    57
     *
jtulach@1379
    58
     *    <li>Two corresponding <tt>double</tt> members whose values
jtulach@1379
    59
     *    are <tt>x</tt> and <tt>y</tt> are considered equal if
jtulach@1379
    60
     *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
jtulach@1379
    61
     *    (Unlike the <tt>==</tt> operator, NaN is considered equal
jtulach@1379
    62
     *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
jtulach@1379
    63
     *
jtulach@1379
    64
     *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
jtulach@1379
    65
     *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
jtulach@1379
    66
     *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
jtulach@1379
    67
     *    definition is recursive for annotation typed members.)
jtulach@1379
    68
     *
jtulach@1379
    69
     *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
jtulach@1379
    70
     *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
jtulach@1379
    71
     *    appropriate overloading of {@link java.util.Arrays#equals}.
jtulach@1379
    72
     * </ul>
jtulach@1379
    73
     *
jtulach@1379
    74
     * @return true if the specified object represents an annotation
jtulach@1379
    75
     *     that is logically equivalent to this one, otherwise false
jtulach@1379
    76
     */
jtulach@1379
    77
    boolean equals(Object obj);
jtulach@1379
    78
jtulach@1379
    79
    /**
jtulach@1379
    80
     * Returns the hash code of this annotation, as defined below:
jtulach@1379
    81
     *
jtulach@1379
    82
     * <p>The hash code of an annotation is the sum of the hash codes
jtulach@1379
    83
     * of its members (including those with default values), as defined
jtulach@1379
    84
     * below:
jtulach@1379
    85
     *
jtulach@1379
    86
     * The hash code of an annotation member is (127 times the hash code
jtulach@1379
    87
     * of the member-name as computed by {@link String#hashCode()}) XOR
jtulach@1379
    88
     * the hash code of the member-value, as defined below:
jtulach@1379
    89
     *
jtulach@1379
    90
     * <p>The hash code of a member-value depends on its type:
jtulach@1379
    91
     * <ul>
jtulach@1379
    92
     * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
jtulach@1379
    93
     *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
jtulach@1379
    94
     *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
jtulach@1379
    95
     *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
jtulach@1379
    96
     *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
jtulach@1379
    97
     *     {@link Long}, {@link Short}, or {@link Boolean}).
jtulach@1379
    98
     *
jtulach@1379
    99
     * <li>The hash code of a string, enum, class, or annotation member-value
jtulach@1379
   100
     I     <tt><i>v</i></tt> is computed as by calling
jtulach@1379
   101
     *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
jtulach@1379
   102
     *     member values, this is a recursive definition.)
jtulach@1379
   103
     *
jtulach@1379
   104
     * <li>The hash code of an array member-value is computed by calling
jtulach@1379
   105
     *     the appropriate overloading of
jtulach@1379
   106
     *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
jtulach@1379
   107
     *     on the value.  (There is one overloading for each primitive
jtulach@1379
   108
     *     type, and one for object reference types.)
jtulach@1379
   109
     * </ul>
jtulach@1379
   110
     *
jtulach@1379
   111
     * @return the hash code of this annotation
jtulach@1379
   112
     */
jtulach@1379
   113
    int hashCode();
jtulach@1379
   114
jtulach@1379
   115
    /**
jtulach@1379
   116
     * Returns a string representation of this annotation.  The details
jtulach@1379
   117
     * of the representation are implementation-dependent, but the following
jtulach@1379
   118
     * may be regarded as typical:
jtulach@1379
   119
     * <pre>
jtulach@1379
   120
     *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
jtulach@1379
   121
     * </pre>
jtulach@1379
   122
     *
jtulach@1379
   123
     * @return a string representation of this annotation
jtulach@1379
   124
     */
jtulach@1379
   125
    String toString();
jtulach@1379
   126
jtulach@1379
   127
    /**
jtulach@1379
   128
     * Returns the annotation type of this annotation.
jtulach@1379
   129
     */
jtulach@1379
   130
    Class<? extends Annotation> annotationType();
jtulach@1379
   131
}