1 /*
   2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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 section 9.6 of
  35  * <cite>The Java&trade; Language Specification</cite>.
  36  *
  37  * @author  Josh Bloch
  38  * @since   1.5
  39  */
  40 public interface Annotation {
  41     /**
  42      * Returns true if the specified object represents an annotation
  43      * that is logically equivalent to this one.  In other words,
  44      * returns true if the specified object is an instance of the same
  45      * annotation type as this instance, all of whose members are equal
  46      * to the corresponding member of this annotation, as defined below:
  47      * <ul>
  48      *    <li>Two corresponding primitive typed members whose values are
  49      *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  50      *    unless their type is <tt>float</tt> or <tt>double</tt>.
  51      *
  52      *    <li>Two corresponding <tt>float</tt> members whose values
  53      *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  54      *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  55      *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  56      *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  57      *
  58      *    <li>Two corresponding <tt>double</tt> members whose values
  59      *    are <tt>x</tt> and <tt>y</tt> are considered equal if
  60      *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  61      *    (Unlike the <tt>==</tt> operator, NaN is considered equal
  62      *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  63      *
  64      *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  65      *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  66      *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
  67      *    definition is recursive for annotation typed members.)
  68      *
  69      *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  70      *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  71      *    appropriate overloading of {@link java.util.Arrays#equals}.
  72      * </ul>
  73      *
  74      * @return true if the specified object represents an annotation
  75      *     that is logically equivalent to this one, otherwise false
  76      */
  77     boolean equals(Object obj);
  78 
  79     /**
  80      * Returns the hash code of this annotation, as defined below:
  81      *
  82      * <p>The hash code of an annotation is the sum of the hash codes
  83      * of its members (including those with default values), as defined
  84      * below:
  85      *
  86      * The hash code of an annotation member is (127 times the hash code
  87      * of the member-name as computed by {@link String#hashCode()}) XOR
  88      * the hash code of the member-value, as defined below:
  89      *
  90      * <p>The hash code of a member-value depends on its type:
  91      * <ul>
  92      * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  93      *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  94      *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  95      *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  96      *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
  97      *     {@link Long}, {@link Short}, or {@link Boolean}).
  98      *
  99      * <li>The hash code of a string, enum, class, or annotation member-value
 100      I     <tt><i>v</i></tt> is computed as by calling
 101      *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
 102      *     member values, this is a recursive definition.)
 103      *
 104      * <li>The hash code of an array member-value is computed by calling
 105      *     the appropriate overloading of
 106      *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
 107      *     on the value.  (There is one overloading for each primitive
 108      *     type, and one for object reference types.)
 109      * </ul>
 110      *
 111      * @return the hash code of this annotation
 112      */
 113     int hashCode();
 114 
 115     /**
 116      * Returns a string representation of this annotation.  The details
 117      * of the representation are implementation-dependent, but the following
 118      * may be regarded as typical:
 119      * <pre>
 120      *   @com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
 121      * </pre>
 122      *
 123      * @return a string representation of this annotation
 124      */
 125     String toString();
 126 
 127     /**
 128      * Returns the annotation type of this annotation.
 129      * @return the annotation type of this annotation
 130      */
 131     Class<? extends Annotation> annotationType();
 132 }