泛型类
public class test1 <T>{
private T a;
public void setA(T a) {
this.a = a;
}
public T getA() {
return a;
}
}
泛型方法
public class test1 {
public <T> T show(T t){
return t;
}
}
泛型接口
public interface test2 <T>{
T show(T t);
}
public class test1<T> implements test2<T>{
public T show(T t) {
return t;
}
}
可变参数
public class test {
public static void main(String[] args) {
System.out.println(sum(10,20,30,40));
}
public static int sum(int...a){
int s = 0;
for (int i:a){
s+=i;
}
return s;
}
}