How to get a JavaDoc of a method at run time?

java, javadoc, oop, runtime

Solution

You can't : the `class` file doesn't contain the comments.

A "solution" would be to generate the javadoc as HTML when you build your program and to build an URL from the name of the class and the name of the method. You could also generate the javadoc in a more suitable format than HTML using the doclet API.

Problem

Its easy to get `a method Name` of a `Class` at run time BUT How i can get a `JavaDoc` of a method at run time ? As the following example Our Class that include `JavaDoc` of our target method ``` public class MyClass { /** * * @param x value of .... * @return result of .... */ public String myMethod(int x) { return "any value"; } } ``` Our Class that has a main method ``` public class TestJava { public static void main(String[] args) { // get Class method Name at run time String methodName = MyClass.class.getMethods()[0].getName(); System.out.println(methodName); // will print myMethod // How to get a JavaDoc of myMethod `method` at run time // MyClass.class.getMethods()[0].???? // expected to print a JavaDoc of myMethod } } ```

Original source

Related problems