Learn the role of java--@override starting from 0

Source: Internet
Author: User

In the morning with the Jsp&servlet study note to learn JSP, after using Eclipse to create a servlet class, found that automatically created classes and books compared to the Doget method, the front of less @override, So I think the eclipse automatically created something that should not have a grammatical problem, if there is no grammatical problem, then why should the author add @override, what role does he have, with such doubts

@override have the role of annotated documents, a little bit like chicken

But it's a very human feature for programmers who are careless.

If you want to rewrite the method of the parent class, such as the ToString () method, precede the overloaded method with @override, so that the system can help you check the correctness of the method when compiling.

As follows

@Override
Public String toString () {...} That's right

If ToString is written as ToString

@Override
Public String ToString () {...} The compiler can detect that this is wrong, reminding you to correct

And if you don't add @override
Public String ToString () {...} So that the compiler will not error, it will be considered as a new method you add in the class

So be careful when programming, not all the wrong system can find



Learn the role of java--@override starting from 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.