Thursday , July 7 2022
Home / Java / JAVA #28 Generics in Java

JAVA #28 Generics in Java

October 16, 2015 Java Leave a comment 1,081 Views

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
package object;
public class ObjectMain {

    public static void main(String[] args) {
           Memory<String> m = new Memory<String>();
class Memory<T>
    private T value;
    public T write() // Getter Function
        return value;
    public void read(T ob) // Setter Function
        value = ob;

About Faheem

An adaptable and responsible Software Engineer, who enjoys working with computers and the opportunity to learn new skills and work with new technologies is particularly attractive to me.

Check Also

JAVA #32 – Java application using SQL server (Part: 01)

  In this part we made the GUI front end of a Application.

Leave a Reply

Your email address will not be published.