OO Programming with Java


Advanced Concepts

Remark. List can serve to pass any number of parameters:

  public static <T> List<T> newList(T... xs) {
	  List<T> ys = new ArrayList<T>();
	  for(T x : xs) ys.add(x);
	  return ys;
  }
  public static void main(String[] args) {
    List<Integer> xs = newList(-1,-2,-1,0,1);
    ...
  }

Such a function already exists in many collections' type, e.g.
List.of(-1,-2,-1,0,1) or Arrays.asList(-1,-2,-1,0,1);


11 - 17