|
| 1 | +# Format |
| 2 | + |
| 3 | +```java,no_run |
| 4 | +import java.io.IOException; |
| 5 | +
|
| 6 | +/// This class serves as a place to put examples |
| 7 | +/// of the different kinds of documentation as well |
| 8 | +/// as how to write documentation properly. |
| 9 | +/// |
| 10 | +/// When specified after the three slashes |
| 11 | +/// you can write documentation using [Markdown](https://en.wikipedia.org/wiki/Markdown). |
| 12 | +/// |
| 13 | +/// In Markdown you can just write text as you would in any file, |
| 14 | +/// line after line. |
| 15 | +/// |
| 16 | +/// # For headings you can use a single hash |
| 17 | +/// |
| 18 | +/// ## For subheadings you can use two |
| 19 | +/// |
| 20 | +/// ### And so on |
| 21 | +/// |
| 22 | +/// You can make unordered lists using hyphens |
| 23 | +/// |
| 24 | +/// - A |
| 25 | +/// - B |
| 26 | +/// - C |
| 27 | +/// |
| 28 | +/// And numbered lists like so |
| 29 | +/// |
| 30 | +/// 1. One |
| 31 | +/// 2. Two |
| 32 | +/// 3. Thre |
| 33 | +/// |
| 34 | +/// And so on. Definitely peruse up [tutorial on markdown](https://www.markdownguide.org/getting-started/) |
| 35 | +/// when you have the time. |
| 36 | +/// |
| 37 | +/// There are some additions specific to Java though. |
| 38 | +/// We call these additions "tags." |
| 39 | +/// |
| 40 | +/// One notable tag is the author tag. It lets you mark who worked |
| 41 | +/// on a given unit of code |
| 42 | +/// |
| 43 | +/// @author Ethan McCue |
| 44 | +/// @see [https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html](https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html) |
| 45 | +public class DocumentationExample { |
| 46 | + /// You can document the purpose of parameters |
| 47 | + /// to constructors and methods with the param tag |
| 48 | + /// |
| 49 | + /// @param o Demonstrates a param tag on a constructor |
| 50 | + public DocumentationExample(Object o) { |
| 51 | +
|
| 52 | + } |
| 53 | +
|
| 54 | + /// Generic parameters can also be documented using the param tag |
| 55 | + /// as well. |
| 56 | + /// |
| 57 | + /// @param item The item to just return back |
| 58 | + /// @param <T> The type of the item. |
| 59 | + public static <T> T identity(T item) { |
| 60 | + return item; |
| 61 | + } |
| 62 | +
|
| 63 | + /// The exceptions thrown by a method can also be documented |
| 64 | + /// to explain under what conditions the exceptions might be thrown |
| 65 | + /// |
| 66 | + /// @param s A parameter to show that throws can be used alongside params |
| 67 | + /// @throws IOException whenever the method is called, no matter what |
| 68 | + public void crash(String s) throws IOException { |
| 69 | + throw new IOException(); |
| 70 | + } |
| 71 | +
|
| 72 | + /// You can reference other classes and methods on those classes with the |
| 73 | + /// link tag. |
| 74 | + /// |
| 75 | + /// For instance {@link String} and {@link String#length()}. |
| 76 | + public void seeMore() { |
| 77 | +
|
| 78 | + } |
| 79 | +} |
| 80 | +``` |
0 commit comments