-1

Every time I let Eclipse generate a field (most often a serial version UID), it adds a comment above it. Example:

/**
 * 
 */
private static final long serialVersionUID = 6347144762354188381L;

This happens because this behavior was for some reason deemed desirable by the developers of Eclipse. I know how to disable it, but that's not the point of this question. I have been developing in java for something like ten years and I have a pretty good understanding of what a good, well-commented code looks like. However, I only rarely add comments above fields and I haven't seen many of those in the wild either.

My question is, what is the reason Eclipse does that? Is it because it is a good practice to comment on generated fields? If so, what information should the comment contain?

  • Probably related: stackoverflow.com/q/996093 – Robert Harvey Jun 7 '18 at 16:01
  • Dear down-voters, did you actually read the question? – JohnEye Jun 8 '18 at 5:35
  • @RobertHarvey That's absolutely unrelated to my question. How did you come to the conclusion that it has anything to do with what I'm asking!? – JohnEye Jun 8 '18 at 5:36
  • FYI in Java there is an annotation @generated : docs.oracle.com/javase/7/docs/api/javax/annotation/… – Walfrat Jun 8 '18 at 7:30
  • @Walfrat: Thanks, are you implying that the reason for the comment field is because I should specify that it was auto-generated? – JohnEye Jun 8 '18 at 8:01
1

The general practice is in order :

  • to have meaningful name of everything so we don't need wall of text to explain what it is when it is possible (most of the time)
  • add comment when necessary

In the specific case you demonstrated it is a serialVersionUID : anyone with a basic skill in Java would know what it means, adding comment add no usefull information. Adding the @Generated annotation would clear the need to explain the field was generated by Eclipse. Also it would state the the value was randomly generatd and not chosen by you, which means you're not managing it and will probably not change the value if you change the class. You can probably set somewhere to not add the default empty bloc comment when generating the field.

Also some tools (like wsimport) that generate code generally add comments that the stuff was generated and with which version, which is important if you encounter any problem.

0

The auto-generated comments aren't just comments, they are also Javadoc comments. So if you run Javadoc on your project, you should get a nice friendly web page documenting all the classes, methods and fields in your code.

But with all the fields having blank documentation, because you haven't filled them in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.