Code example for InvocationHandler

Methods: invoke

0
     */ 
    public String toString() {
        String result =  null;
        try { 
            // invocation is also generated 
            result = (String) handler.invoke(this, Object.class.getMethod("toString", (Class[])null), null);
        } catch (ClassCastException e) {
            throw e;
        } catch (NoSuchMethodException e) {
            // ignore, the method has to be found, as this class is generated 
        } catch (RuntimeException e) {
            throw e;
        } catch (Error e) {
            throw e;
        } catch (Throwable e) {
            throw new UndeclaredThrowableException(e);
        } 
        return result;
    } 
 
}