Ii. JavaSE _ set (generic) and javase set generic
Generic
I. Overview of generics
1. Preliminary understanding
First, let's look at what is generic?
1 List list = new ArrayList (); // no generic constraints 2 List <String> list = new ArrayList <String> (); // a generic Constraint
View Code
The first line of code does not carry out generic constraints, that is, the list can store objects of the type. Then there will be security risks. Next, we will talk about security risks.
The second line of code isGenericIn other words, the second list can only store data of the String type. Note: After jdk1.7, you can also define it as follows: List <String> list = new ArrayList <> (); that is, the subsequent types can be left empty.
Let's take a look at the Collection API
The e-generation table is composed of elements)
The E represents the generic type.
2. Benefits of generics
- Improved security (converting runtime errors to compilation)
- Eliminating the hassle of strong Conversion
If any error occurs, please correct it.
Email: it_chang@126.com