Explain the role of @ override in Java

Explain the role of @ override in Java

@Override is pseudo code, which means rewriting (of course, it's OK not to write it), but it has the following advantages:

1. Can be used as notes for easy reading;

2. The compiler can verify whether the method name under @ override is all in your parent class. If not, an error will be reported. For example, if you don't write @ override and you write the following method name wrong, your compiler can compile it because the compiler thinks this method is an added method in your subclass.

For example, when overriding oncreate of the parent class, adding @ override to the method can help you check the correctness of the method.

This is correct if you write:

The compiler will report the following error: the method oncreate (bundle) of type HelloWorld must override or implement a supertype method to ensure that you correctly override the oncreate method (because oncreate should be oncreate). If you do not add @ override, the compiler will not detect the error, but will think that you have defined a new method for the subclass: oncreate

If you have any questions, please leave a message or go to the community of this site for exchange and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

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
分享
二维码
< <上一篇
下一篇>>