class Template<Type extends Object> {
private Type template;
public Template() { }
public Template(Type template) { setTemplate(template); }
public void setTemplate(Type template) { this.template = template; }
public Type getTemplate() { return template; }
public void Myprint() { System.out.println(template.toString());
}
public static void main(String[] args) {
Template<String> stringT = new Template<String>();
stringT.setTemplate(new String("Hello Template class"));
stringT.Myprint();
Template<Integer> integerT = new Template<Integer>(5);
integerT.Myprint();
Template doubleT = new Template<Double>(3.1415926);
doubleT.Myprint();
Template<Student> studentT=new Template<Student>();
studentT.setTemplate(new Student("lyz",23));
studentT.Myprint();
}
}
public class Student {
private String name;
private int age;
public Student(String name,int age){
this.name=name;
this.age=age;
}
@Override
public String toString() {
String str="name:"+name+"||age:"+age;
return str;
}
}