Java - Add bounding to generic: Any Class that is parent of double class

Description

Add bounding to generic: Any Class that is parent of double class

Demo

import java.util.ArrayList;
import java.util.List;

public class SimpleMain02 {
  public static void main(String[] args) {

    show(new ArrayList<Double>() {
      {/*from  ww  w . ja  v a 2s .  c  o  m*/
        add(10.23);
        add(20.234);
        add(30.34);
      }
    });

  }

  // Any Class that is parent of double class
  public static void show(List<? super Double> lst) {
    for (Object n : lst)
      System.out.println(n);
  }
}

Related Topic