In summary, generics have the following two advantages over non-generics:
1. More secure
In non-generic programming, although everything can be passed as an object, type conversion is inevitable during the transfer process. Type conversion is not safe at runtime. Using generic programming can reduce unnecessary type conversion and improve security.
2. Higher efficiency
In non-generic programming, passing a simple type as an object will cause boxing and unboxing operations, both of which are very open-ended. With generic programming, you do not need to perform boxing and unboxing operations.
. Net generics have good binary reusability. This is because. Net has built generics into CLR. In C ++ generics and evaluation, Java generics rely on the features provided by their respective compilers.CodeExpand the exact type, which will inevitably lead to code expansion problems. The. NET generic code is compiled by JIT at runtime, so that CLR can reuse most of the real-time compilation code for different types.
Original article address