Java covariant return

Source: Internet
Author: User

That is to say, the parent class and the Child class remain in the same form.

In java5.0, as long as the subclass method has the same method signature as the superclass method, or the return value of the subclass method is the subtype of the superclass method, it can be overwritten.

In object-oriented language, a method indicates that when a subclass overwrites A superclass method, the return value of the method can be replaced by a "narrower" type.

For example:

List

The Iterator function obtains the Iterator of the current set. In the subclass, The Iterator has a more precise representation, so the ListIterator subclass of Iterator is used as the new return value.

: "Covariant return" is allowed only when the return type of subclass (subclass) is superclass (parent class) return type extension (inheritance.

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.