How can I obtain the default value for a type in Java?
<p>I'm writing a wrapper that calls a method, and if an exception is thrown, logs it and returns a default value.</p>

<pre><code>InvocationHandler invocationHandler = new InvocationHandler() {
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        try {
            return invokeOn(wrapped, method, args);
        } catch (InvocationTargetException e) {
            Throwable targetException = e.getTargetException();
            if (targetException instanceof Exception) {
                errorReporter.exception(wrapped, (Exception) targetException);
                return defaultValueFor(method.getReturnType());
            } else {
                throw targetException;
            }
        }
    }
};
</code></pre>

<p>I'd like to find a nice way of implementing defaultValueFor so that it returns a good default value for each possible type - the equivalent of </p>

<pre><code>@SuppressWarnings("unchecked")
protected static &lt;T&gt; T defaultValueFor(Class&lt;T&gt; claz) {
    if (claz == boolean.class)
        return (T) Boolean.FALSE;
    if (claz == short.class)
        return (T) Short.valueOf((short) 0);
    if (claz == int.class)
        return (T) Integer.valueOf(0);
    if (claz == long.class)
        return (T) Long.valueOf(0);
    ...
    return null;
}
</code></pre>

<p>This sort of code must be in JMock etc, but is there a nicer implementation than this horrible boiler-plate?</p>
