Introduction

Generics allow you to define the specification of the data type of programming elements in a class or a method until it is actually used in the program. In other words, generics allow you to write a class or method that can work with any data type.

Features of Generics

Generics is a technique that makes your programs in the following ways,

Generic Methods

We can declare a generic method with a type parameter. The following program illustrates the concept.

When code is executed then the result is,