Java – how do I prevent eclipse from moving my line comments after comments?

I set some comments on the class and comment on the same line as the comments, for example:

@SampleAnnotation // sample comment
@AnotherAnnotation // another comment
public class SampleClass { }

However, every time I format the file, my comments on the same line eventually move to the next line Not only is it unpopular because it changes my comments, but what's worse is that it places comments in a confusing place The above sample becomes:

@SampleAnnotation
// sample comment
@AnotherAnnotation
// another comment
public class SampleClass { }

How do I prevent eclipse from moving these comments after formatting? Or, how can I have eclipse move comments to the top line instead of the bottom line? thank you.

Solution

By far, the best solution is to tell eclipse to close the formatter for these blocks That is, the original code will become:

// @formatter:off
@SampleAnnotation // sample comment
@AnotherAnnotation // another comment
// @formatter:on
public class SampleClass { }

Make sure the off / on tag is enabled in Eclipse:

>From the main menu, access windows → preferences. > On the left, access Java → code style → formatter. > On the right, click Edit

>If you are using a built-in profile, you must change the name at the top of the dialog box in the profile name field

>Click OK After the dialog box closes, click OK again to finish applying the settings

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>