|
53 | 53 | * |
54 | 54 | * @author Curtis Rueden |
55 | 55 | */ |
56 | | -public abstract class Nil<T> implements GenericTyped, Proxyable<T>, |
57 | | - InvocationHandler |
58 | | -{ |
| 56 | +public abstract class Nil<T> implements GenericTyped, Proxyable<T> { |
59 | 57 |
|
60 | 58 | /** Generic type of the object. */ |
61 | 59 | private final TypeToken<?> typeToken; |
@@ -192,26 +190,27 @@ public T proxy() { |
192 | 190 | // NB: Technically, this cast is not safe, because T might not be |
193 | 191 | // an interface, and thus might not be one of the proxy's types. |
194 | 192 | @SuppressWarnings("unchecked") |
195 | | - final T proxy = (T) Proxy.newProxyInstance(loader, interfaces, this); |
196 | | - return proxy; |
197 | | - } |
198 | | - |
199 | | - // -- InvocationHandler methods -- |
| 193 | + final T proxy = (T) Proxy.newProxyInstance(loader, interfaces, |
| 194 | + new InvocationHandler() { |
| 195 | + @Override |
| 196 | + public Object invoke(final Object proxy, final Method method, |
| 197 | + final Object[] args) throws Throwable |
| 198 | + { |
| 199 | + try { |
| 200 | + // Look for a Nil subclass method of the same signature. |
| 201 | + final Method m = callbacks.getClass().getMethod(method.getName(), // |
| 202 | + method.getParameterTypes()); |
| 203 | + return m.invoke(callbacks, args); |
| 204 | + } |
| 205 | + catch (final NoSuchMethodException exc) { |
| 206 | + // NB: Default behavior is to do nothing and return null. |
| 207 | + return Classes.nullValue(method.getReturnType()); |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | + ); |
200 | 212 |
|
201 | | - @Override |
202 | | - public Object invoke(final Object proxy, final Method method, |
203 | | - final Object[] args) throws Throwable |
204 | | - { |
205 | | - try { |
206 | | - // Look for a Nil subclass method of the same signature. |
207 | | - final Method m = callbacks.getClass().getMethod(method.getName(), // |
208 | | - method.getParameterTypes()); |
209 | | - return m.invoke(callbacks, args); |
210 | | - } |
211 | | - catch (final NoSuchMethodException exc) { |
212 | | - // NB: Default behavior is to do nothing and return null. |
213 | | - return Classes.nullValue(method.getReturnType()); |
214 | | - } |
| 213 | + return proxy; |
215 | 214 | } |
216 | 215 |
|
217 | 216 | // -- Helper methods -- |
|
0 commit comments