fork download
  1. class Example<N extends Number, D extends Double> {
  2. N nullAsNumber() { return null; }
  3. D nullAsDouble() { return null; }
  4.  
  5. public static void main(String[] args) {
  6. System.out.println(System.getProperty("java.version"));
  7. Example<Double, Double> e = new Example<>();
  8.  
  9. try {
  10. Double a = false ? 0.0 : e.nullAsNumber();
  11. System.out.printf("a == %f%n", a);
  12. Double b = false ? 0.0 : e.nullAsDouble();
  13. System.out.printf("b == %f%n", b);
  14.  
  15. } catch (NullPointerException x) {
  16. System.out.println(x);
  17. }
  18. }
  19. }
Success #stdin #stdout 0.06s 27936KB
stdin
Standard input is empty
stdout
1.8.0_112
a == null
java.lang.NullPointerException