泛型类

  1. public class test1 <T>{
  2. private T a;
  3. public void setA(T a) {
  4. this.a = a;
  5. }
  6. public T getA() {
  7. return a;
  8. }
  9. }

泛型方法

  1. public class test1 {
  2. public <T> T show(T t){
  3. return t;
  4. }
  5. }

泛型接口

  1. public interface test2 <T>{
  2. T show(T t);
  3. }
  4. public class test1<T> implements test2<T>{
  5. public T show(T t) {
  6. return t;
  7. }
  8. }

可变参数

  1. public class test {
  2. public static void main(String[] args) {
  3. System.out.println(sum(10,20,30,40));
  4. }
  5. public static int sum(int...a){
  6. int s = 0;
  7. for (int i:a){
  8. s+=i;
  9. }
  10. return s;
  11. }
  12. }