Java-Generic commentary

Source: Internet
Author: User
1. Only reference data types can be loaded in the collection, and basic data types cannot be loaded. For example, a numeric value of type int 123 is automatically boxed. 2. The data type of the developer loading the collection is not deterministic, so it is designed to fit all of the objects. 3. The new problem arises, and the data that is loaded into the collection loses the original data type and becomes object. The type conversion is required when this is taken out. and if the type conversion error is a run-time error, load a dog and turn it into a cat . We try to advance the error ahead to the compile time. 4, the collection of generics, each time the collection element is loaded, the compiler will check whether the same as the original provisions. You don't need to change the elements when you take them out. 5. List<object> is not the parent of list<person>, and there is no inheritance relationship between them. If you can inherit, a problem arises, and we can add elements of different data types, such as Integer, Double, Byte, and so on in the List<number> collection. Generics are meant to constrain the types of elements that are added to the inside, which is contradictory.

Java-Generic commentary

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.