Java泛型相关知识
标签:one nbsp list string set ring xtend setvalue ati
Java里面的泛型在实际开发中运用的很多,比如分页插件,List接口的实现类ArrayList。
public class ArrayList extends AbstractList implements List
public static void main(String[] args) {
List mylist=new ArrayList();
}
}
一个简单的泛型
public class MyObjectextends BaseData {
private T valueOne;
private T valueTwo;
public MyObject(T valueOne, T valueTwo) {
this.valueOne = valueOne;
this.valueTwo = valueTwo;
}
public T getValueOne() {
return valueOne;
}
public void setValueOne(T valueOne) {
this.valueOne = valueOne;
}
public T getValueTwo() {
return valueTwo;
}
public void setValueTwo(T valueTwo) {
this.valueTwo = valueTwo;
}
public static void main(String[] args) {
MyObject object = new MyObject("String one!", "String two");
System.out.println("value one " + object.valueOne + " value two " + object.valueTwo);
}
}
Java泛型相关知识
标签:one nbsp list string set ring xtend setvalue ati
原文地址:https://www.cnblogs.com/santiagohome/p/13373977.html
评论