Michal Kordas
Michal Kordas

Reputation: 10925

Escape unicode escaping within Javadoc

I'm writing Javadoc for a class explaining proper unicode escaping:

 * String unitAbbrev = "μs"; //Best: perfectly clear even without a comment.
 * String unitAbbrev = "\u03bcs"; //Poor: the reader has no idea what this is.

Unfortunately they both render with "μs":

enter image description here

Is there any way to escape this unicode escape?

Double backslash ("\\u03bcs") doesn't work:

enter image description here

Upvotes: 2

Views: 536

Answers (2)

dimo414
dimo414

Reputation: 48794

You can alternatively use the HTML escape \, which still isn't great when read from source, but it's at least clearly not a unicode escape.

The only disadvantage of HTML escapes is they don't work inside {@code ...} blocks (they're rendered verbatim), so you need to use <pre> and <code> instead.

It seems like \\ should work as javac appears to handle it correctly, but javadoc isn't.

Upvotes: 2

drrob
drrob

Reputation: 642

Try putting the escaped Unicode literal for the backslash itself, I think:

\u005c

Upvotes: 2

Related Questions