🔥 Burn Fat Fast. Discover How! 💪

JEP 413: Code Snippets in Java API Documentation #jep #javadoc | Java Tech News

JEP 413: Code Snippets in Java API Documentation
#jep #javadoc #documentation
This JEP introduces a @snippet tag for JavaDoc's Standard Doclet, to simplify the inclusion of example source code in API documentation. Especially, the best feature in this JEP is "external snippets". External snippets are useful because they allow the example code to be written in separate files that can be directly edited in an IDE, and which can be shared between multiple related snippets. Up until Java 18 you have to update every {@code ..,} snippet manually. With this change you can create a reference like that:
/**
* {@snippet file="ShowOptional.java" region="example"}
*/
where ShowOptional.java is a file containing:
public class ShowOptional {
void show(Optional v) {
// @start region="example"
if (v.isPresent()) {
System.out.println("v: " + v.get());
}
// @end
}
}
https://openjdk.java.net/jeps/413