Generics in java
package com.company;
import java.util.ArrayList;
class myGeneric<T,T2>{
int val;
T t;
T2 t2;
public int getVal() {
return val;
}
public void setVal(int val) {
this.val = val;
}
public T getT() {
return t;
}
public void setT(T t) {
this.t = t;
}
public T2 getT2() {
return t2;
}
public void setT2(T2 t2) {
this.t2 = t2;
}
public myGeneric(int val, T t, T2 t2) {
this.val = val;
this. t = t;
this.t2=t2;
}
}
public class CWH_110_Generics {
public static void main(String[] args) {
ArrayList arrayList= new ArrayList();
arrayList.add("Rohan");
arrayList.add(478);
arrayList.add('3');
arrayList.add(789);
int a= (int) arrayList.get(3);
System.out.println(a);
myGeneric<String,Character> obj= new myGeneric(65,"Rohan kumar",'r');
System.out.println(obj.getT());
System.out.println(obj.getT2());
}
}
Comments
Post a Comment