Skip to content

Commit 181e962

Browse files
authored
How to choose which signature annotation to use
1 parent 039b405 commit 181e962

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

docs/manual/signature-checker.tex

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@
176176
\end{description}
177177
178178
179+
\subsectionAndLabel{How to choose which annotation to use}{signature-choosing-annotation}
180+
181+
Sometimes, there are multiple valid annotations for a value. As an
182+
example, a non-primitive non-array type is represented identically by
183+
\<@BinaryName>, \<@ClassGetName>, and \<@FqBinaryName>. Using the lowest
184+
type in the type hierarchy (in this case, \<@BinaryName>) has two
185+
advantages. First, it acts as documentation that the value is never a
186+
primitive or array. Second, it permits the value to be used in any of the
187+
three contexts: as a \<@BinaryName>, a \<@ClassGetName>, or a
188+
\<@FqBinaryName>.
189+
190+
Casting to \<@BinaryName> from one of the other types adds clutter if it is not
191+
necessary. Suppose that a method returns a \<@ClassGetName> and the value will
192+
only be used in contexts that require a \<@ClassGetName> (say, it is passed to a
193+
method that requires an argument of that type). Then there is no point in
194+
casting to \<@BinaryName> in between, even if you know the type being
195+
represented is not a primitive or an array.
196+
197+
179198
\sectionAndLabel{What the Signature Checker checks}{signature-checks}
180199
181200
Certain methods in the JDK, such as \<Class.forName>, are annotated
@@ -196,4 +215,5 @@
196215
% LocalWords: jls getName ClassGetName ClassLoader LMyClass Ljava jvms
197216
% LocalWords: DotSeparatedIdentifiers CharSequence Lmypackage mypackage
198217
% LocalWords: FieldDescriptorWithoutPackage InternalForm getSimpleName
199-
% LocalWords: ClassGetSimpleName FqBinaryName CanonicalName
218+
% LocalWords: ClassGetSimpleName FqBinaryName CanonicalName checkers''
219+
% LocalWords: Lpkg

0 commit comments

Comments
 (0)