泛型范例
来源:互联网 发布:交大知行大厦附近租房 编辑:程序博客网 时间:2024/04/29 23:27
interface Info
{
}
class Person<T extends Info>
{
private T information;
public Person(T information)
{
this.setInformation(information);
}
public void setInformation(T information)
{
this.information = information;
}
public T getInformation()
{
return this.information;
}
public String toString()
{
return this.information.toString();
}
}
class Wei implements Info
{
private String province;
private String street;
private String zipcode;
public Wei(String province,String street,String zipcode)
{
this.setProvince(province);
this.setStreet(street);
this.setZipcode(zipcode);
}
public void setProvince(String province)
{
this.province = province;
}
public String getProvince()
{
return this.province;
}
public void setStreet(String street)
{
this.street = street;
}
public String getStreet()
{
return this.street;
}
public void setZipcode(String zipcode)
{
this.zipcode = zipcode;
}
public String getZipcode()
{
return this.zipcode;
}
public String toString()
{
return "city: " + getProvince() +
"street: " + getStreet() +
"zipcode: " + getZipcode();
}
}
class Int implements Info
{
private String name;
private String sex;
private int age;
public Int(String name,String sex,int age)
{
this.setName(name);
this.setSex(sex);
this.setAge(age);
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getSex()
{
return this.sex;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return this.age;
}
public String toString()
{
return "name: " + getName() +
"sex: " + getSex() +
"age: " + getAge();
}
}
public class Demo110
{
public static void main(String args[])
{
Person<Wei> per = new Person<Wei>( new Wei("beijing","guangdong","45133"));
//Person<Int> per = new Person<Int>( new Int("JIM","男",23));
System.out.println(per);
}
}
{
}
class Person<T extends Info>
{
private T information;
public Person(T information)
{
this.setInformation(information);
}
public void setInformation(T information)
{
this.information = information;
}
public T getInformation()
{
return this.information;
}
public String toString()
{
return this.information.toString();
}
}
class Wei implements Info
{
private String province;
private String street;
private String zipcode;
public Wei(String province,String street,String zipcode)
{
this.setProvince(province);
this.setStreet(street);
this.setZipcode(zipcode);
}
public void setProvince(String province)
{
this.province = province;
}
public String getProvince()
{
return this.province;
}
public void setStreet(String street)
{
this.street = street;
}
public String getStreet()
{
return this.street;
}
public void setZipcode(String zipcode)
{
this.zipcode = zipcode;
}
public String getZipcode()
{
return this.zipcode;
}
public String toString()
{
return "city: " + getProvince() +
"street: " + getStreet() +
"zipcode: " + getZipcode();
}
}
class Int implements Info
{
private String name;
private String sex;
private int age;
public Int(String name,String sex,int age)
{
this.setName(name);
this.setSex(sex);
this.setAge(age);
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setSex(String sex)
{
this.sex = sex;
}
public String getSex()
{
return this.sex;
}
public void setAge(int age)
{
this.age = age;
}
public int getAge()
{
return this.age;
}
public String toString()
{
return "name: " + getName() +
"sex: " + getSex() +
"age: " + getAge();
}
}
public class Demo110
{
public static void main(String args[])
{
Person<Wei> per = new Person<Wei>( new Wei("beijing","guangdong","45133"));
//Person<Int> per = new Person<Int>( new Int("JIM","男",23));
System.out.println(per);
}
}
0 0
- 泛型操作范例
- 泛型范例
- 泛型操作范例
- c# 泛型应用范例
- 范例
- 范例
- 〖泛型〗_实例讲解—泛型操作范例笔记
- 〖泛型〗_实例讲解—泛型操作范例笔记
- Trriger 范例
- CSS范例
- 工程范例
- 范例1
- 文档范例
- 数据库连接范例
- SI 范例
- 绘图范例
- AJAX 范例
- 脚本范例
- 软件工程个人项目--词频统计
- 讲空值转换为实际值
- 二十岁出头,你一无所有,但你却拥有一切,因为你还有牛逼的梦想。 可那又怎样,只有行动,才能解除你所有的不安
- "高可用方案工具包" high availability toolkit 1.1
- CF - 475 - D. CGCDSSQ(枚举)
- 泛型范例
- 深度探索java对象模型
- 两段提交协议
- MapReduce实验:Hive安装以及简单操作
- HTTP协议入门
- 指针,引用,与按值传递
- Excel中如何以文字而不是图片的方式将内容复制到QQ中
- xcode-C语言出接触_选择排序
- Curl命令详解