Skip to main content
edited punctuations
Source Link
Vinoth Kumar C M
  • 15.7k
  • 23
  • 60
  • 86

Is it a good practice to write comments for widely known methods like equals, compareTo etc.?

Consider the below code.

 /**
 * This method compares the equality of the current object 
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }   

My company madates to enter comments like the above.Is the above Javadoc comment required.? Is it not obvious and well understood thatwhat the equals method and the likes (compare,compareTo) etc does .?

What are your suggestions?

Is it a good practice to write comments for widely known methods like equals, compareTo etc.

Consider the below code.

 /**
 * This method compares the equality of the current object 
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }   

My company madates to enter comments like the above.Is the above Javadoc comment required. Is it not obvious and well understood that equals method and the likes (compare,compareTo) etc does .

What are your suggestions?

Is it a good practice to write comments for widely known methods like equals, compareTo etc?

Consider the below code.

 /**
 * This method compares the equality of the current object 
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }   

My company madates to enter comments like the above.Is the above Javadoc comment required? Is it not obvious and well understood what the equals method and the likes (compare,compareTo) etc does?

What are your suggestions?

Source Link
Vinoth Kumar C M
  • 15.7k
  • 23
  • 60
  • 86

Writing documentation for well understood methods like equals in Java

Is it a good practice to write comments for widely known methods like equals, compareTo etc.

Consider the below code.

 /**
 * This method compares the equality of the current object 
  with the object of same type
 */
@Override
public boolean equals(Object obj) {

               //code for equals

     }   

My company madates to enter comments like the above.Is the above Javadoc comment required. Is it not obvious and well understood that equals method and the likes (compare,compareTo) etc does .

What are your suggestions?