Author: Jiangnan Baiyi
Too many books have been written in the generic Syntax of Java 5. But to really understand the use of generic programming, we still need to go back to its hometown C ++. We can only learn syntax through examples in Java.
GP must be useful. Otherwise, Java and C # will not be able to support GP at the same time. But we also know that the GP and Python-based Dynamic oo languages are different in ideology. If they are one vote, I think most of them are civilians.ProgramMembers are more keen on the plain nature of dynamic oo languages.
My heartless usage of GP:
Summarize the following three functions of generics:
The first is generalization. You can use a t to represent any type. However, GP is forced out by the strict static nature of C ++. It falls into the plain of Hua Yu such as Java and C #. All objects are derived from objects except several primitive types, the same can be very generic, so the Java Collection class has a good experience without a paradigm. With the Java reflection function, GP does not take much advantage in terms of universality.
The second is convergence, which increases type security and reduces forced type conversion.Code. This is a weakness of Java Collection.
Third, you can build many things during the compilation period, such as metaprogramming. However, unless they can be completely enclosed in the framework, users and extensions of the framework do not need to learn the usage of these things. Otherwise, they are solely at the People's box office. C ++'s metaprogramming is amazing, but by comparing Python's simple Syntax of creating a class with meta programming, we can see what is truly a good call and a great call.
Therefore, as an architecture designer, we should only use the convergence characteristics in the three characteristics of Java generics to make the framework more secure in the spirit of being responsible to the people, less forced type conversion.
In addition, the implementation of the Java GP wiping method ensures that the framework's model features are available and optional to users.
The wiping method avoids Java's bleeding split:
We often scold Java GP for its wiping method, but I think thanks to its moderate feature-if you use it as a model, you don't need to use it as a common object, this prevents the Java camp from going through a split to be or not to be.
The biggest example is the collection framework of Java 5. For example, some students insist that they will not be an idiot for type errors, furthermore, it is hard to bear that a generic definition list (goods) must be included in each definition 〉 You don't need to force type conversion. The code saved here is not enough (by the way, there is no tyepdef... in Java .....), therefore, it is very difficult for the model to catch a cold. At this time, we would like to thank you for this dirty wipe method so that you can still maintain a Non-generic usage for a generic framework...
SeriesArticle:
Java framework writing (1) -- Preface
Java framework programming (2)-boring usage of generics and platforms for wiping Methods
Java framework programming (3) -- fragment about reflection
Java framework programming (4) -- Annotation vs XML vs interface the latest round
Java framework programming (5) -- cglib Application
Framework programming in Java (6) -- ASM (to be written)