Generics in Java
In a Java, generics enable types (classes and interfaces) to be parameters when defining classes, interfaces and methods. Much like the more familiar formal parameters used in method declarations, type parameters provide a way for you to re-use the same code with different inputs. The difference is that the inputs to formal parameters are values, while the inputs to type parameters are types.
File name ObjectMain.java package object; public class ObjectMain { public static void main(String[] args) { Memory<String> m = new Memory<String>(); m.read(23.21+"Faheem"); System.out.println(m.write()); } } class Memory<T> { private T value; public T write() // Getter Function { return value; } public void read(T ob) // Setter Function { value = ob; } }