4 回答
For inline code in Javadocs,you should use {@code your-code-here}
See javadoc - {@code text}
for more details.
Equivalent to
<code>{@literal text}</code>
.Displays text in
code
font without interpreting the text as HTML markup or nested javadoc tags. ..
From the W3C on TT.
HTML Reference
The element is a non-standard element.
HTML5 classifies it as a non-conforming feature.
Examples
No, really, don't use it.
And I think that answers the question. Choice of 2 elements, W3C says do not use one of them.
The code tag is preferred as tt is a font style element and as of HTML 4, styling by style sheets is preferred to font style elements.
There is little practical difference between code
and tt
, i.e. software that processes HTML documents treats them the same way: they are by default treated as inline elements, rendered in a browser-dependent monospace font and possibly (depending on browser) in reduced font size. A distinction between them is mostly just theoretic talk. However, some automatic translation software makes a difference, treating code
as having non-translatable content.
So there is some advantage in using code
, but it is more important that you consider the real implications of either markup. If you don’t want reduced font size, set font-size: 100%
. If you don’t want browser’s default monospace, which tends to be Courier New, set font-family
.