I had a really tough time with including a specific code example in a javadoc comment. I'd like to share this one.
Please note the following:
- usage of old
<code>- tag to prevent the curly brackets from being interpreted - usage of "new"
{@code ...}- tag to get the generics included in the output - escaping of the @ sign in
@Overridevia "{@literal @}Override" because javadoc generator "tilts" there due to the fact that the @ goes directly after an opening curly bracket - remove one space in front of
{@codeand{@literal, to compensate inner spaces and keep the alignment
javadoc code:
/** this methods adds a specific translator from one type to another type. ` * i.e. * <pre> * <code>new BeanTranslator.Builder() * .translate( * new Translator{@code <StringTranslator<String, Integer>}(String.class, Integer.class){ * {@literal @}Override * public Integer translate(String instance) { * return Integer.valueOf(instance); * }}) * .build(); * </code> * </pre> * @param translator */ gets printed as
new BeanTranslator.Builder() .translate( new Translator<String, Integer>(String.class, Integer.class){ @Override public Integer translate(String instance) { return Integer.valueOf(instance); }}) .build();