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) { ... }
@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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With