java
1public class Sum00 {
2 public static void main(String[] args) {
3 System.out.println(addition(1, 2));
4 System.out.println(addition(new Integer(1), new Integer(2)));
5 System.out.println(addition(Integer.MAX_VALUE, Integer.MAX_VALUE));
6 System.out.println(addition(Integer.MIN_VALUE, Integer.MIN_VALUE));
7 try {
8 System.out.println(addition(1, null));
9 } catch(Exception e) {
10 System.out.println(e);
11 }
12 }
13
14 public static Long addition(final Integer a, final Integer b) throws NullPointerException {
15 if (a == null) {
16 throw new NullPointerException("a: null");
17 }
18 if (b == null) {
19 throw new NullPointerException("b: null");
20 }
21 return (long)a + b;
22 }
23}
実行例