From the course: Java: Generic Classes

Advantages of generics - Java Tutorial

From the course: Java: Generic Classes

Advantages of generics

- [Instructors] Let us now talk about the advantages of the benefits of the Generics concept. The first one is compile and runtime protection. We know now that Generics always will do the type safety checks at the compilation stage itself. These type safe checks will then avoid all the potential problems that you encounter at runtime. So it gives you compile and runtime protection. Secondly, you do not have to do any kind of explicit casting in order to process your values inside the Generics code. The compiler will do that implicit casting for you. This essentially means that you do not introduce any kind of clutter, and your code is always clean and robust. Lastly, Generics have a way to define operations that can be performed on a varied number of types. This essentially will give you a chance to develop generic algorithms. Generics is a very powerful feature in the Java language. Ensure that you always write your code with Generics.

Contents