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