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

Save This Page
Home » openjdk-7 » java » lang » annotation » [javadoc | source]