Java wildcard character types

Source: Internet
Author: User

Java wildcard character types

@author Ixenos

  • wild-Letter wildcard type
    • The subtype qualification of the wildcard character (? are all grandchildren)

        • < extends T>
        • pair<? extends Employee > managerrr = new pair< Manager > (CEO,CFO); Manager is the employee subclass, where covariant (generic wildcard types can be covariant, and generic generics are not covariant)

        • type pair<? Extends Employee> method://? Is the manager's subclass
          • void Setfirst (? Extends Employee)  //not callable, compiler only knows? The range of values is grandchildren, do not know what the specific type (? Refuse to pass any particular type)
          • extends Employee GetFirst ()//callable, return value is covariant, passing the return value of any employee subtype to the employee reference is covariant (manifested polymorphism)
    • The wildcard character's super-type qualification (? are fathers)
      • <? Super t>
        • Type pair<? Super Manager> Method://? It's the manager's parent class.
          • void Setfirst (? Super Manager)//callable, the compiler does not know that the specific parameter is that the employee object cannot be called because it is not necessarily a father, but can be any Manager object or its subclasses
          • ? Super Manager GetFirst ()//non-callable, return type is open Papa, may be modified in class or not necessarily, cannot guarantee type safety, can only return object

        

Java wildcard character types

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.