What are generics in Java? What are the benefits of using generics?

Generics are a new feature of Java SE1.5. The essence of generics is a parameterized type, which means that the data type being manipulated is specified as a parameter.
Benefits:

  • Type safety, providing type checking during compilation
  • Front and back compatible
  • Generalized code, code can be reused more
  • The performance is relatively high, the code written in GJ (generic Java) can bring more type information to the Java compiler and virtual machine, which provides conditions for further optimization of the Java program

Guess you like

Origin blog.csdn.net/qq_43518425/article/details/114138103
Recommended