1. /*
  2. * @(#)Annotation.java 1.9 04/06/18
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.lang.annotation;
  8. /**
  9. * The common interface extended by all annotation types. Note that an
  10. * interface that manually extends this one does <i>not</i> define
  11. * an annotation type. Also note that this interface does not itself
  12. * define an annotation type.
  13. *
  14. * @author Josh Bloch
  15. * @since 1.5
  16. */
  17. public interface Annotation {
  18. /**
  19. * Returns true if the specified object represents an annotation
  20. * that is logically equivalent to this one. In other words,
  21. * returns true if the specified object is an instance of the same
  22. * annotation type as this instance, all of whose members are equal
  23. * to the corresponding member of this annotation, as defined below:
  24. * <ul>
  25. * <li>Two corresponding primitive typed members whose values are
  26. * <tt>x</tt> and <tt>y</tt> are considered equal if <tt>x == y</tt>,
  27. * unless their type is <tt>float</tt> or <tt>double</tt>.
  28. *
  29. * <li>Two corresponding <tt>float</tt> members whose values
  30. * are <tt>x</tt> and <tt>y</tt> are considered equal if
  31. * <tt>Float.valueOf(x).equals(Float.valueOf(y))</tt>.
  32. * (Unlike the <tt>==</tt> operator, NaN is considered equal
  33. * to itself, and <tt>0.0f</tt> unequal to <tt>-0.0f</tt>.)
  34. *
  35. * <li>Two corresponding <tt>double</tt> members whose values
  36. * are <tt>x</tt> and <tt>y</tt> are considered equal if
  37. * <tt>Double.valueOf(x).equals(Double.valueOf(y))</tt>.
  38. * (Unlike the <tt>==</tt> operator, NaN is considered equal
  39. * to itself, and <tt>0.0</tt> unequal to <tt>-0.0</tt>.)
  40. *
  41. * <li>Two corresponding <tt>String</tt>, <tt>Class</tt>, enum, or
  42. * annotation typed members whose values are <tt>x</tt> and <tt>y</tt>
  43. * are considered equal if <tt>x.equals(y)</tt>. (Note that this
  44. * definition is recursive for annotation typed members.)
  45. *
  46. * <li>Two corresponding array typed members <tt>x</tt> and <tt>y</tt>
  47. * are considered equal if <tt>Arrays.equals(x, y)</tt>, for the
  48. * appropriate overloading of {@link java.util.Arrays#equals}.
  49. * </ul>
  50. *
  51. * @return true if the specified object represents an annotation
  52. * that is logically equivalent to this one, otherwise false
  53. */
  54. boolean equals(Object obj);
  55. /**
  56. * Returns the hash code of this annotation, as defined below:
  57. *
  58. * <p>The hash code of an annotation is the sum of the hash codes
  59. * of its members (including those with default values), as defined
  60. * below:
  61. *
  62. * The hash code of an annotation member is (127 times the hash code
  63. * of the member-name as computed by {@link String#hashCode()}) XOR
  64. * the hash code of the member-value, as defined below:
  65. *
  66. * <p>The hash code of a member-value depends on its type:
  67. * <ul>
  68. * <li>The hash code of a primitive value <tt><i>v</i></tt> is equal to
  69. * <tt><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</tt>, where
  70. * <tt><i>WrapperType</i></tt> is the wrapper type corresponding
  71. * to the primitive type of <tt><i>v</i></tt> ({@link Byte},
  72. * {@link Character}, {@link Double}, {@link Float}, {@link Integer},
  73. * {@link Long}, {@link Short}, or {@link Boolean}).
  74. *
  75. * <li>The hash code of a string, enum, class, or annotation member-value
  76. I <tt><i>v</i></tt> is computed as by calling
  77. * <tt><i>v</i>.hashCode()</tt>. (In the case of annotation
  78. * member values, this is a recursive definition.)
  79. *
  80. * <li>The hash code of an array member-value is computed by calling
  81. * the appropriate overloading of
  82. * {@link java.util.Arrays#hashCode(long[]) Arrays.hashCode}
  83. * on the value. (There is one overloading for each primitive
  84. * type, and one for object reference types.)
  85. * </ul>
  86. *
  87. * @return the hash code of this annotation
  88. */
  89. int hashCode();
  90. /**
  91. * Returns a string representation of this annotation. The details
  92. * of the representation are implementation-dependent, but the following
  93. * may be regarded as typical:
  94. * <pre>
  95. * @com.acme.util.Name(first=Alfred, middle=E., last=Neuman)
  96. * </pre>
  97. *
  98. * @return a string representation of this annotation
  99. */
  100. String toString();
  101. /**
  102. * Returns the annotation type of this annotation.
  103. */
  104. Class<? extends Annotation> annotationType();
  105. }