class WrapperClass{
private Object object;
public void add(Object object) {
this.object = object;
}
public Object get() {
return object;
}
}
class Demo {
public static void main(String[] args) {
WrapperClass integer= new GenericClass();
integer.add(new Integer(10));
Integer someInteger = (Integer)integer.get();
System.out.println(someInteger);
/*GenericClass str=new GenericClass();
str.add("10");
someInteger=(Integer)str.get();//String can not be cast with
integer at run time.*/
}
}
private Object object;
public void add(Object object) {
this.object = object;
}
public Object get() {
return object;
}
}
class Demo {
public static void main(String[] args) {
WrapperClass integer= new GenericClass();
integer.add(new Integer(10));
Integer someInteger = (Integer)integer.get();
System.out.println(someInteger);
/*GenericClass str=new GenericClass();
str.add("10");
someInteger=(Integer)str.get();//String can not be cast with
integer at run time.*/
}
}
No comments:
Post a Comment