---restore content starts---
Java Learning Week Tenth
this week, learn generic programming, generics are also known as parameterized types (parameterized type), that is, when defining classes, interfaces, and methods, the type parameter indicates the type of object that will be processed (such as the ArrayList Class). Generic program setting (genericprogramming) means that writing code can be reused by many different types of objects. It is important to note that the generic attribute is forward-compatible.
the greatest benefits of generics are considered by individuals: eliminating the forced type conversion makes the code more readable and reduces the chances of error; the benefits of introducing generics into the Java language are simple and secure. The benefit of generics is that it checks for type safety at compile time, and all casts are automatic and implicit, increasing the rate of reuse of the code.
generic class definition: Add <> after the class name, and then add the type parameter, such as Class pair<t>, a generic class can have more than one type variable. For example: public class pair<t, u> {...}. (type variables are capitalized). Sometimes, classes, interfaces, or methods need to constrain type variables, such as examples Pair1 and pair2 in books, with the qualification of generic variables:
1, whether the qualification is a class or interface, unified use the keyword extends
2, can use the & symbol to give a number of limits
3, if there is a limit to the existing interface and class, then the class must be only one, and placed in the first place
After practicing the annotation of the sample program, I helped me understand the knowledge of the generic class better, but the knowledge of the inheritance rules of the generic type is a little vague, it will seek help in the book and blog Park, and other tools can help us to solve the problem of learning.
---restore content ends---
201671010140.2016-2017-2 Java Program Tenth week of Java learning