package
com.java2novice.generics;
public
class
MySimpleGenerics {
public
static
void
main(String a[]){
SimpleGeneric sgs =
new
SimpleGeneric(
"JAVA2NOVICE"
);
sgs.printType();
SimpleGeneric sgb =
new
SimpleGeneric(Boolean.TRUE);
sgb.printType();
}
}
/**
* Here T is a type parameter, and it will be replaced with
* actual type when the object got created.
*/
class
SimpleGeneric{
private
T objReff =
null
;
public
SimpleGeneric(T param){
this
.objReff = param;
}
public
T getObjReff(){
return
this
.objReff;
}
public
void
printType(){
System.out.println(
"Type: "
+objReff.getClass().getName());
}
}
No comments:
Post a Comment