Java – Generics

Java – Generics

A generic class/method is the class/method that declares one or more type variables. With generic classes/method we skip the creation of multiple classes/method because of different type variables Generic Method Example One generic method instead overloading a method like this below: Generic Class Example: Restrictions: You cannot instantiate primitives, you should use their wrapper class. ex: use Integer instead of int You cannot declare static fields whose types are type parameters You cannot create new instances of type parameters. Diamond parameter <>: You can just use an empty pair of…

Java – Generics Read More