Rule Definition
There is no dispute that these comments contribute to a developer's understanding and help a developer write reliable applications more quickly. Without documenting returned value, it is dififcult for anyone else than the author to guess its purpose except by looking at the code that is using it.
Remediation
Add @return tag for every method that returns something other than void
Violation Code Sample
public class AddNum { public int addNum(int numA, int numB) { //VIOLATION:No @return tag. return numA + numB; } /** * This is the main method which makes use of addNum method. * @param args Unused. * @exception IOException On input error. * @see IOException */ public static void main(String args[]) throws IOException { //No Violation since the method is not returning anything. AddNum obj = new AddNum(); int sum = obj.addNum(10, 20); System.out.println("Sum of 10 and 20 is :" + sum); } }
Fixed Code Sample
Remediation Sample: ------------------ public class AddNum { /** * This method is used to add two integers. This is * a the simplest form of a class method, just to * show the usage of various javadoc Tags. * @param numA This is the first paramter to addNum method * @param numB This is the second parameter to addNum method * @return int This returns sum of numA and numB. //Fixed */ public int addNum(int numA, int numB) { return numA + numB; } }
Reference
https://www.oracle.com/technetwork/java/javase/documentation/index-137868.html#@exception https://developer.atlassian.com/server/confluence/javadoc-standards/
Related Technologies
JEE
Technical Criterion
Documentation - Automated Documentation
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.