class N<K> {
K obj;
N(K obj)
{
this.obj=obj;
}
public K getObject()
{
return this.obj;
}
}
class temp
{
public static void main(String[] args)
{
N<Double> a=new N<Double>(100.10); //Double type should not be allowed in generics
N<String> b=new N<String>("hi");
N<Integer> c=new N<Integer>(100);
System.out.println(a.getObject()); // 'print 100.10'
System.out.println(b.getObject()); // 'print hi'
System.out.println(c.getObject()); // 'print 100'
}
}
Our code accepts all Type of data but i want only it to accept Integer and String type and other type should not be used ? How can i achieve the desired result.