Home | History | Annotate | Download | only in annotation
      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  * The {@link java.lang.reflect.AnnotatedElement} interface discusses
     38  * compatibility concerns when evolving an annotation type from being
     39  * non-repeatable to being repeatable.
     40  *
     41  * @author  Josh Bloch
     42  * @since   1.5
     43  */
     44 public interface Annotation {
     45     /**
     46      * Returns true if the specified object represents an annotation
     47      * that is logically equivalent to this one.  In other words,
     48      * returns true if the specified object is an instance of the same
     49      * annotation type as this instance, all of whose members are equal
     50      * to the corresponding member of this annotation, as defined below:
     51      * <ul>
     52      *    <li>Two corresponding primitive typed members whose values are
     53      *    <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
     54      *    unless their type is <tt>float</tt> or <tt>double</tt>.
     55      *
     56      *    <li>Two corresponding <tt>float</tt> members whose values
     57      *    are <tt>x</tt> and <tt>y</tt> are considered equal if
     58      *    <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
     59      *    (Unlike the <tt>==</tt> operator, NaN is considered equal
     60      *    to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
     61      *
     62      *    <li>Two corresponding <tt>double</tt> members whose values
     63      *    are <tt>x</tt> and <tt>y</tt> are considered equal if
     64      *    <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
     65      *    (Unlike the <tt>==</tt> operator, NaN is considered equal
     66      *    to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
     67      *
     68      *    <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
     69      *    annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
     70      *    are considered equal if <tt>x.equals(y)</tt>.  (Note that this
     71      *    definition is recursive for annotation typed members.)
     72      *
     73      *    <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
     74      *    are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
     75      *    appropriate overloading of {@link java.util.Arrays#equals}.
     76      * </ul>
     77      *
     78      * @return true if the specified object represents an annotation
     79      *     that is logically equivalent to this one, otherwise false
     80      */
     81     boolean equals(Object obj);
     82 
     83     /**
     84      * Returns the hash code of this annotation, as defined below:
     85      *
     86      * <p>The hash code of an annotation is the sum of the hash codes
     87      * of its members (including those with default values), as defined
     88      * below:
     89      *
     90      * The hash code of an annotation member is (127 times the hash code
     91      * of the member-name as computed by {@link String#hashCode()}) XOR
     92      * the hash code of the member-value, as defined below:
     93      *
     94      * <p>The hash code of a member-value depends on its type:
     95      * <ul>
     96      * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
     97      *     <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
     98      *     <tt><i>WrapperType</i></tt> is the wrapper type corresponding
     99      *     to the primitive type of <tt><i>v</i></tt> ({@link Byte},
    100      *     {@link Character}, {@link Double}, {@link Float}, {@link Integer},
    101      *     {@link Long}, {@link Short}, or {@link Boolean}).
    102      *
    103      * <li>The hash code of a string, enum, class, or annotation member-value
    104      I     <tt><i>v</i></tt> is computed as by calling
    105      *     <tt><i>v</i>.hashCode()</tt>.  (In the case of annotation
    106      *     member values, this is a recursive definition.)
    107      *
    108      * <li>The hash code of an array member-value is computed by calling
    109      *     the appropriate overloading of
    110      *     {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
    111      *     on the value.  (There is one overloading for each primitive
    112      *     type, and one for object reference types.)
    113      * </ul>
    114      *
    115      * @return the hash code of this annotation
    116      */
    117     int hashCode();
    118 
    119     /**
    120      * Returns a string representation of this annotation.  The details
    121      * of the representation are implementation-dependent, but the following
    122      * may be regarded as typical:
    123      * <pre>
    124      *   &#064;com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
    125      * </pre>
    126      *
    127      * @return a string representation of this annotation
    128      */
    129     String toString();
    130 
    131     /**
    132      * Returns the annotation type of this annotation.
    133      * @return the annotation type of this annotation
    134      */
    135     Class<? extends Annotation> annotationType();
    136 }
    137