泛型接口的实现方式一:在子类的定义上声明泛型类型
2016-04-04 16:50
441 查看
/*泛型接口的实现方式一:在子类的定义上声明泛型类型*/
interface Info6<T>{
public T getVar();
}
class Infoimpl<T> implements Info6<T>{ //在子类的定义上声明泛型类型
private T var;
public Infoimpl(T var){
this.setVar(var);
}
public void setVar(T var){
this.var = var;
}
public T getVar(){
return this.var;
}
}
public class GenericsInterfaceDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Info6<String> i = null;
i = new Infoimpl<String>("张三");
System.out.println("内容:"+i.getVar());
}
}
interface Info6<T>{
public T getVar();
}
class Infoimpl<T> implements Info6<T>{ //在子类的定义上声明泛型类型
private T var;
public Infoimpl(T var){
this.setVar(var);
}
public void setVar(T var){
this.var = var;
}
public T getVar(){
return this.var;
}
}
public class GenericsInterfaceDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Info6<String> i = null;
i = new Infoimpl<String>("张三");
System.out.println("内容:"+i.getVar());
}
}
相关文章推荐
- 笔试题15. LeetCode OJ (2)
- 关于PHP
- CopyOnWriteArrayList与Collections.synchronizedList的性能对比
- ios 总结
- 序列化机制
- C++之多态
- hdoj 1434 幸福列车【模拟】
- 杭电2602-0-1背包模板题
- 通过泛型方法返回泛型类实例
- Python 学习之二:Python超短教程
- 面试题11 数值的整数次方
- xcode plugin
- mysql索引总结----mysql 索引类型以及创建
- spark sql 基本用法
- nginx重试机制-重新发起请求导致的问题
- jar10
- 基于tigase服务器的安卓客户端开发---创建聊天
- OpenCV HOG
- 定义一个泛型方法
- String StringBuilder StringBuffer