Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No line break after @Override annotation?

When overriding methods, android studio automatically inserts a line break after the @Override annotation.

How can I have the IDE insert the @Override without the line break and have it immediately followed by the method declaration (ie on the same line ?):

@Override public Fragment getItem(int position) { ... } 

instead of:

@Override public Fragment getItem(int position) { ... } 
like image 912
Running Turtle Avatar asked Apr 21 '14 07:04

Running Turtle


People also ask

What is @override annotation used for?

@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance. While it is not required to use this annotation when overriding a method, it helps to prevent errors.

What happens if you don't use @override Java?

If you don't use the annotation, the sub-class method will be treated as a new method in the subclass (rather than the overriding method). 2) It improves the code's readability.

When should @override be used?

The annotation @Override is used for helping to check whether the developer what to override the correct method in the parent class or interface. When the name of super's methods changing, the compiler can notify that case, which is only for keep consistency with the super and the subclass.

Is it necessary to use @override in Java?

It is not necessary, but it is highly recommended. It keeps you from shooting yourself in the foot. It helps prevent the case when you write a function that you think overrides another one but you misspelled something and you get completely unexpected behavior.


1 Answers

File -> Settings -> Code Style -> Wrapping and Braces -> Method annotations and set to Do not wrap.

Note: Changing the setting will not actually reformat all existing ones. It just won't be wrapped when inserted automatically by the IDE, as you want in your question. This applies to all annotations for methods.

enter image description here

like image 74
singularhum Avatar answered Oct 03 '22 02:10

singularhum