Let's say we have following code:
public void a(String a) {
if (a == null) {
throw new IllegalArgumentException();
}
}
public void b(Queue<Integer> b) {
if (b == null) {
throw new IllegalArgumentException();
}
}
public void c(Stack<Integer> c) {
if (c == null) {
throw new IllegalArgumentException();
}
}
Is it possible to write a method that do the throw new exception job ? That is something like this:
public void a(String a) {
check(a);
}
public void b(Queue<Integer> b) {
check(b);
}
public void c(Stack<Integer> c) {
check(c);
}
Notice that their types of parameter is not the same.
void check(Object o) { if (o == null) { throw new IllegalArgumentException(); } }?