Generics
Generics are a great way to prevent bugs at runtime since they provide compile-time type checking and promote cast elimination. Another important advantage of using generics is that you can write code that uses abstractions instead of concrete classes, so you can create maintainable and extendable code.
The following example shows how we can print a collection containing different types using generics:
import java.util.List; import java.util.Arrays; public class ListPrinter { private <T> void printList(List<T> collection){ for(T item: collection){ System.
[Read More]