Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get generics in javadoc code block displayed?

I have a javadoc code block where I want to write a code sample that includes generics like this:

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) { ... }

The javadoc output is:

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 Generic is missing in the output.

How can I get javadoc to display the generics correctly?

like image 218
confile Avatar asked Mar 17 '23 13:03

confile


1 Answers

Java doc is rendered to HTML, so anything between angular brackets (<>) would be interpreted as an HTML tag, and won't be printed as text. You can use &lt; and &gt; in order to render HTML < and > respectively:

 /**
   * 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
   */
like image 170
Mureinik Avatar answered Apr 01 '23 07:04

Mureinik