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™ 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 * {@code x} and {@code y} are considered equal if {@code x == y},
54 * unless their type is {@code float} or {@code double}.
55 *
56 * <li>Two corresponding {@code float} members whose values
57 * are {@code x} and {@code y} are considered equal if
58 * {@code Float.valueOf(x).equals(Float.valueOf(y))}.
59 * (Unlike the {@code ==} operator, NaN is considered equal
60 * to itself, and {@code 0.0f} unequal to {@code -0.0f}.)
61 *
62 * <li>Two corresponding {@code double} members whose values
63 * are {@code x} and {@code y} are considered equal if
64 * {@code Double.valueOf(x).equals(Double.valueOf(y))}.
65 * (Unlike the {@code ==} operator, NaN is considered equal
66 * to itself, and {@code 0.0} unequal to {@code -0.0}.)
67 *
68 * <li>Two corresponding {@code String}, {@code Class}, enum, or
69 * annotation typed members whose values are {@code x} and {@code y}
70 * are considered equal if {@code x.equals(y)}. (Note that this
71 * definition is recursive for annotation typed members.)
72 *
73 * <li>Two corresponding array typed members {@code x} and {@code y}
74 * are considered equal if {@code Arrays.equals(x, y)}, 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 <i>{@code v}</i> is equal to
97 * <code><i>WrapperType</i>.valueOf(<i>v</i>).hashCode()</code>, where
98 * <i>{@code WrapperType}</i> is the wrapper type corresponding
99 * to the primitive type of <i>{@code v}</i> ({@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 <i>{@code v}</i> is computed as by calling
105 * <code><i>v</i>.hashCode()</code>. (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 * @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