When you are in your pen, you have been learning Java for 5 days. It is used to C , and now I look at Java, there is a feeling of a life. Java and C have a lot of places, and there are also some different places. In fact, think carefully, these differences do not explain that better, mainly the design ideas of the two languages, different targets: C focused efficiency, Java pays attention to safety. Their differences will also be launched, of course, I have written this article not to explain them, but I feel one thing, remember seems to be Java claims to support GP (perhaps the next version, maybe it has been implemented However, I just started learning, I didn't see the relevant books, I didn't know the situation now), a little doubt: STL's father has tried in Java, and the result talked at the end, no Know what technology is used this GP introduced Java. People who have used STL know that this is a typical example of achieving GP in C . So what is the GP? What is the implementation of GP? First we said that generic is generally defined: Abstract of Genreic Concepts. GP is Generic Programming Abbreviation, meaning: Abstract of Generic Concepts and the subsequent instantiation, and some say GP is Programming With Concepts. From these definitions, we can see that the Concept in GP is in a very important position, then what is Concept? The definition of books according to the "Van Dynamic Programming and STL" is: a set of "describes a certain type" condition. You can imagine Concept as a set of types, or you can imagine a collection of other collections, and even imagine a set of legitimate programs, no matter how they are in nature. If we define Concept in accordance with the formal specification system, maybe Concept is: a Set of Many-sorted Algebas, which is strictly defined by mathematical logic. Personally think that GP is a kind of thought, the core of thinking is to realize the type independence in the program design by static algorithms and dynamic operations, in a close way, low coupling characteristics. The implementation of GP in C is implemented by template more inheritance, of course, more basic is an operator overload. The Template in C acquires the improvement of running efficiency by time loss during compilation, while performing parameter detection by the compiler, high security. This is why STL's parent chooses C to achieve a very important place to achieve its own STL, after all, language direct support can be more convenient and more efficient. Of course, it is not to say that GP can only be implemented in C . GP is a kind of thought. It should be independent of any language. Java is not also claimed to join GP? However, the introduction of GP in C has a great advantage, the characteristics of the language itself (template multi-inheritance) make C have a unique advantage: there is high security while lossless efficiency. So what is Java to support GP? I am a little doubt.
There is no template in Java, and there is no more inheritance. Of course, the single inheritance in Java may be more advantageous, and there is a good RTTI mechanism in Java (at least more than the RTTI in C , maybe C is too weak. . However, there are also some problems to consider that, for example, the basic type of Java is not an object. Single features are not used by them, this is more distressed. In addition, the single RTTI itself is not realized with the law itself. It is achieved by the theoretical class library system of OOP. This seems to be more intuitive, but the characteristics of the RTTI runtime will undoubtedly be a huge obstacle. If Java does not care, this seems to have no more pain, but RTTI does not have a compiler as a compiler like C , but in the contrary, he has bypass the type inspection mechanism, deceives the compiler, and the security problem has emerged. This security guarantee is very reluctant to return to the programmer's hand. This is a very depressed place. Maybe Java has its own way, let us wait and see. Note: Now it is said that Java will introduce the template, then it is almost the same as C :)