Java Generics

 public class Parent {

public static void main(String[] args){

// generic class constructor 

Test<Integer> list = new Test<Integer>();

list.setvalue(12);

System.out.println(list.getvalue());

}

}

class Test<T> {

// global variable of type T

T objvalue;

// method setter 

public void setvalue(T objvalue){

    this.objvalue = objvalue;

}

// method getter 

public T getvalue(){

    return this.objvalue;

}

}

=====================================================

 public class Parent {

public static void main(String[] args){

// generic class constructor 

Test<Integer> list = new Test<Integer>(12);

System.out.println(list.getvalue());

}

}

class Test<T> {

// global variable of type T

T objvalue;

// method setter 

public Test(T objvalue){

    this.objvalue = objvalue;

}

// method getter 

public T getvalue(){

    return this.objvalue;

}

}


Comments

Popular posts from this blog

java on terminal

typing using javascript html css