136

Suppose, that as part of documenting your code (Javadoc) you want to indicate that the relationships between elements using deep indentation.

How can I create a nested list as:

  • some element
    • some other element
      • yet some other element
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
James Raitsev
  • 92,517
  • 154
  • 335
  • 470

3 Answers3

187
<ul>
  <li>Element</li>
  <ul>
     <li>Subelement...</li>

You can pretty freely use HTML inside javadoc comments.

Update: Because it came up, I tried

<ul>
    <li>one</li>
    <ul>
        <li>one point one</li>
    </ul>   
</ul>

and get

  • one
    • one point one

I agree proper nesting is better.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263
  • 2
    I'd say nested
      has to be inside some
    • element, for comparison see http://www.w3.org/wiki/HTML_lists#Nesting_lists
    – user2622016 Sep 05 '13 at 08:37
  • You can say that, but trying it says something different. – Charlie Martin Sep 06 '13 at 19:46
  • 2
    @Charlie Instead of saying "I agree proper nesting is better.", maybe You could write an example showing how to properly nest? Otherwise, maybe some beginner will not understand Your comment and use the above-mentioned form. – Rauni Lillemets Apr 24 '14 at 07:35
  • 2
    I understood that user2622016 meant that You have to write like this:
      • ...
    , so that the innermost
      ..
    is also inside a
  • ..
  • block. – Rauni Lillemets Apr 25 '14 at 11:59
  • I don't see any difference between example 1 and example 2, so it's hard to say which one is "proper nesting". – Noumenon Nov 20 '16 at 04:46
  • Sadly, someone with an editing bug up their butt "corrected" the examples, making the answer incomprehensible.The point is that `
    • xxx
    • YYY
    ` will render correctly, but that `
    • xxx
      • YYY
    `, being correctly nested, is better.
    – Charlie Martin Nov 20 '16 at 08:40
  • 3
    One thing to do, though, is remove the `` tags. They are not supposed to be there. JavaDoc isn't HTML, although it borrows from it. Same for `` tags, which you shouldn't use in JavaDoc. – SeverityOne Apr 18 '18 at 06:47
  • @SeverityOne that wasn't the case when I was a Java Architect at Sun, and reviewing the standard I don't immediately see anything to that effect now, so I guess I'd like a citation. – Charlie Martin Apr 18 '18 at 19:23
  • 3
    Although I cannot find it explicitly stated (and I did look), it's the style that is used in [Oracle's documentation](http://www.oracle.com/technetwork/java/javase/tech/index-137868.html). Also, NetBeans complains about it. Intellij, on the other hand, happily adds the `` tags – SeverityOne Apr 18 '18 at 20:37