Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add javadoc to a static initializer in Java?

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?

like image 414
tttppp Avatar asked Jun 23 '11 13:06

tttppp


2 Answers

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.

like image 196
Matt Avatar answered Sep 28 '22 01:09

Matt


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.

like image 36
Andy Thomas Avatar answered Sep 28 '22 01:09

Andy Thomas