Annotation.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* Annotation.java - Base interface for all annotations
  2. Copyright (C) 2004 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.lang.annotation;
  32. /**
  33. * This is the common interface for all annotations. Note that classes
  34. * that implement this class manually are not classed as annotations, and
  35. * that this interface does not define an annotation type in itself.
  36. *
  37. * @author Tom Tromey (tromey@redhat.com)
  38. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  39. * @since 1.5
  40. */
  41. public interface Annotation
  42. {
  43. /**
  44. * Returns the type of this annotation.
  45. *
  46. * @return the class of which this annotation is an instance.
  47. */
  48. Class<? extends Annotation> annotationType();
  49. /**
  50. * <p>
  51. * Returns true if the supplied object is equivalent to this annotation.
  52. * For this property to hold, the following must be true of <code>o</code>:
  53. * </p>
  54. * <ul>
  55. * <li>The object is also an instance of the same annotation type.</li>
  56. * <li>The members of the supplied annotation are equal to those of this
  57. * annotation, according to the following:
  58. * <ul>
  59. * <li>If the members are <code>float</code>s, then, for floats
  60. * <code>x</code> and <code>y</code>,
  61. * <code>Float.valueOf(x).equals(Float.valueOf(y)</code> must return
  62. * true. This differs from the usual (<code>==</code>) comparison
  63. * in that <code>NaN</code> is considered equal to itself and positive
  64. * and negative zero are seen as different.</li>
  65. * <li>Likewise, if the members are <code>double</code>s, then, for doubles
  66. * <code>x</code> and <code>y</code>,
  67. * <code>Double.valueOf(x).equals(Double.valueOf(y)</code> must return
  68. * true. This differs from the usual (<code>==</code>) comparison
  69. * in that <code>NaN</code> is considered equal to itself and positive
  70. * and negative zero are seen as different.</li>
  71. * <li>Strings, classes, enumerations and annotations are considered
  72. * equal according to the <code>equals()</code> implementation for these
  73. * types.</li>
  74. * <li>Arrays are considered equal according to <code>Arrays.equals()</code>
  75. * </li>
  76. * <li>Any remaining types are considered equal using <code>==</code>.</li>
  77. * </li>
  78. * </ul>
  79. *
  80. * @param o the object to compare with this annotation.
  81. * @return true if the supplied object is an annotation with equivalent
  82. * members.
  83. */
  84. boolean equals(Object o);
  85. /**
  86. * <p>
  87. * Returns the hash code of the annotation. This is computed as the
  88. * sum of the hash codes of the annotation's members.
  89. * </p>
  90. * <p>
  91. * The hash code of a member of the annotation is the result of XORing
  92. * the hash code of its value with the result of multiplying the hash code
  93. * of its name by 127. Formally, if the value is <code>v</code> and the
  94. * name is <code>n</code>, the hash code of the member is
  95. * v.hashCode() XOR (127 * String.hashCode(n)). <code>v.hashCode()</code>
  96. * is defined as follows:
  97. * </p>
  98. * <ul>
  99. * <li>The hash code of a primitive value (i.e. <code>byte</code>,
  100. * <code>char</code>, <code>double</code>, <code>float</code>,
  101. * <code>int</code>, <code>long</code>, <code>short</code> and
  102. * <code>boolean</code>) is the hash code obtained from its corresponding
  103. * wrapper class using <code>valueOf(v).hashCode()</code>, where
  104. * <code>v</code> is the primitive value.</li>
  105. * <li>The hash code of an enumeration, string, class or other annotation
  106. * is obtained using <code>v.hashCode()</code>.</li>
  107. * <li>The hash code of an array is computed using
  108. * <code>Arrays.hashCode(v)</code>.</li>
  109. * </ul>
  110. *
  111. * @return the hash code of the annotation, computed as the sum of its
  112. * member hashcodes.
  113. */
  114. int hashCode();
  115. /**
  116. * Returns a textual representation of the annotation. This is
  117. * implementation-dependent, but is expected to include the classname
  118. * and the names and values of each member.
  119. *
  120. * @return a textual representation of the annotation.
  121. */
  122. String toString();
  123. }