Representation of generics

Source: Internet
Author: User

Generic type:
* Generics are types in Java
* Java.lang.Type can represent all types in Java
* Generics are parameterized types
* Type--->class
* Parameterized-->class type can pass parameters
* Meaning of the existence of generics
* polymorphic
Actual type and required type may not match
ClassCastException errors are reported if they do not match
* Generics can tell class type at compile time, pass parameters
is what type, if the type is wrong, then at compile time will be
Error
* The form represented by generics
* arraylist<t>
* ArrayList is class type
* ArrayList with a parameter of t,t is a formal parameter
* When creating a ArrayList object, you can determine the argument
* Performance:arraylist<person> a = new arraylist<person> ();
This argument is person, which means that only the person is stored in a collection
* Public Interface persondao<t>{

}
public class basedaoimpl<t>{

}
public class Persondaoimpl extends basedaoimpl<person> implements persondao<person>{

}
* public class person<? Extends collection> passed parameters can only be subclasses of the collection
* Usage of generics
public class person<t>{

}
The parameter T can be used on properties and methods (which can be used on the parameters and return values of the method)

Representation of generics

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.