Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty trailing comments? Do they do/mean anything?

Tags:

java

I'm looking at some of the code in the Android butterknife library and found this snippet here:

  private static final List<Class<? extends Annotation>> LISTENERS = Arrays.asList(//
      OnCheckedChanged.class, //
      OnClick.class, //
      OnEditorAction.class, //
      OnFocusChange.class, //
      OnItemClick.class, //
      OnItemLongClick.class, //
      OnItemSelected.class, //
      OnLongClick.class, //
      OnPageChange.class, //
      OnTextChanged.class, //
      OnTouch.class //
  );

I found this a bit peculiar to have what looks like just empty comments after each line, but no comment text. It reminded me a little of line continuation in C macros, but I have never come across this before in java.

Does this actually accomplish anything / is there some convention here where this is used?

like image 388
FatalError Avatar asked Oct 06 '14 16:10

FatalError


People also ask

What is a trailing comment?

Trailing comments describe the action or use of a single line of code. They are usually start (and end) on the same line as the code they are commenting.

What is a trailing comment in Java?

2.3. Trailing comments are used to provide an explanation for a single line of code. Begin trailing comments with a double slash ( // ) and place them to the right of the line of code they reference.


1 Answers

The only purpose I'm aware of is to prevent auto-indent from moving the next line up. For example, on my system without the // end of line comments, an auto-indent yields

private static final List<Class<? extends Annotation>> LISTENERS = Arrays
        .asList(OnCheckedChanged.class, OnClick.class,
                OnEditorAction.class, OnFocusChange.class,
                OnItemClick.class, OnItemLongClick.class,
                OnItemSelected.class, OnLongClick.class,
                OnPageChange.class, OnTextChanged.class, OnTouch.class);
like image 151
Elliott Frisch Avatar answered Oct 05 '22 11:10

Elliott Frisch