Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to explicitly comment empty methods?

public void destroy() {
}

I have written above empty method in my filter class which is required as per the interface. But when my code goes to PMD check it mentions

Uncommented Empty Method finds instances where a method does not contain statements, but there is no comment. By explicitly commenting empty methods it is easier to distinguish between intentional (commented) and unintentional empty methods.

I do not understand it. What really does it mean?

like image 658
Madhu Sudhan Reddy Avatar asked Nov 05 '25 22:11

Madhu Sudhan Reddy


1 Answers

When you have a method with an empty body, it is possible that you started writing the method and then forgot to insert the body. If you intend for the method to be empty, you should make a note (in a comment) to explain that it's empty on purpose. In the case of Filter, since you have to implement the destroy() method, you should write a comment that says something like "nothing to clean up".

like image 185
chrylis -cautiouslyoptimistic- Avatar answered Nov 08 '25 15:11

chrylis -cautiouslyoptimistic-