I have refactored a class and moved some code from the constructor to a static initializer. What should I do with the javadoc that was on the constructor? Is it possible to add javadoc to a static initializer?
First and foremost, it's arguable if static initializers are good practice to start with.
If you decide to use them nevertheless, I'd add the documentation to the JavaDoc at the class level. Static initializers can, depending on how they're implemented, cause side-effects. If you use static initializers with side-effects, the behaviour should be documented for the consumer of said class.
JavaDoc is intended primarily to document the interface of the class. JavaDoc comments must precede a class, field, constructor or method declaration.
A static initializer is not part of the interface. It's part of the implementation of the class.
You could document its behavior in the class documentation, if desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With