Advanced Java Tutorial

Total available pages count: 55
Subject - Java Technologies

Generic class

The class that can be referred to as any type is called generic class. The parament of the T type is used to create a generic class of a specific type.

/* creating Generic class */
class Mygen<T>
	T obj;
	Void add(T obj)
	T get()
		return obj;


The T type defines that can refer to any type of data type i.e., String, Integer ...etc. It specifies a class that can be used to store or retrieve elements.

Type Parameter

The Type meter naming conventions are important to learn generics.

    T – Type
    E – Element
    K – Key
    N – Number
    V – Value

The Generics classes are used to create a generic method that used to accept any type of argument. the scope of argument is limited to the method where it allows static as well as non-static methods.