How can I get generics in javadoc code block?

I have a javadoc code block where I want to write a sample code that includes such common files:

public interface SomeInterface <T> { }
public interface SomeInterface extends SomeOtherInterface<T> { }

Here is my javadoc block:

  /**
   * Get the Generic Type T of a Type (Class/Interface) or extended/inherited Subtype: 
   * <pre>
   * {@code
   * public interface SomeInterface <T> { }
   * public interface SomeInterface extends SomeOtherInterface<T> { }
   * }
   * </pre>
   * @param implType
   * @param parentType
   * @return
   */
  public static JClassType findGenericType(JClassType implType, JClassType parentType) { ... }

Javadoc output:

Get the Generic Type T of a Type (Class/Interface) or extended/inherited Subtype:


 public interface SomeInterface  { }
 public interface SomeInterface extends SomeOtherInterface { }
 }

Parameters:
implType
parentType
Returns:

The output is missing a common parameter.

How can I get javadoc to display generics correctly?

+4
source share
3 answers

The Java document is displayed in HTML, so anything between the angular brackets ( <>) will be interpreted as an HTML tag and will not print as text. You can use &lt;both &gt;for rendering HTML <and >accordingly:

 /**
   * Get the Generic Type T of a Type (Class/Interface) or extended/inherited Subtype: 
   * <pre>
   * {@code
   * public interface SomeInterface &lt;T&gt; { }
   * public interface SomeInterface extends SomeOtherInterface&lt;T&gt; { }
   * }
   * </pre>
   * @param implType
   * @param parentType
   * @return
   */
+4
source

JavaDoc html . , , JavaDoc angular (<) angular ( > ), &lt; angular &gt; angular . :

/**
* Get the Generic Type T of a Type (Class/Interface) or extended/inherited Subtype: 
* <pre>
* {@code
* public interface SomeInterface &lt;T&gt; { }
* public interface SomeInterface extends SomeOtherInterface&lt;T&gt; { }
* }
* </pre>
* @param implType
* @param parentType
* @return
*/

. .

+1

What about?

/**
 * Explain something...
 * <pre>
 * public interface SomeInterface &lt;T&gt; { }
 * </pre>
 */

This is because the JavaDoc is displayed as HTML, so it <>must be escaped for proper rendering.

Edit: After clarifying with OP, I changed the answer.

0
source

Source: https://habr.com/ru/post/1568542/


All Articles