On 10/02/2018 06:54 AM, Nir Lisker wrote:
Hi,
Many static methods are used to obtain an instance of a class,
functioning as a de-facto constructor and sometimes replacing it
altogether. These are factory or builder methods and the like.
The problem is that while they function as constructors, they are
hidden between the rest of the methods in the JavaDoc. It is my
understanding that the Constructors section shows how to create an
instance, while the Methods section shows how to use it. In this case,
the aforementioned methods will fit better in the Constructors section.
One way this can be solved is via an annotation on the method that
would list it under the Constructors, used at the developers
discretion. As an example, Toolkit is a singleton:
public class Toolkit {
private final Toolkit TOOLKIT;
private Toolkit() { ... }
@Constructor
public static getDefaultSystemToolkit() { return TOOLKIT; }
}
The annotation shows the intended way for a developer to obtain the
instance.
I can submit an RFE if this is plausible. Otherwise, I'm open for
other solutions if you agree with the problem I presented.
- Nir
Nir,
It's not an unreasonable request, and has been suggested before, dating
back to 2002.
That being said, there has not been sufficient interest to make it happen.
See this JBS issue for one of the early requests:
https://bugs.openjdk.java.net/browse/JDK-4619333
-- Jon