MultiMethod { @SuppressWarnings("unchecked") public R call(T object, Object parameter) throws Throwable { Optional<MethodHandle> handle = cached.computeIfAbsent(parameter.getClass(), type -> find(object, parameter, returned, method)); if (handle.isPresent()) { return (R) handle.get().invoke(object, parameter); } return null; } private  MultiMethod(Class<T> forClass, Class<R> returned, String method, MethodHandles.Lookup lookup); static GrabMethod<T> in(Class<T> targetClass); @SuppressWarnings("unchecked") R call(T object, Object parameter); MultiMethod<T, R> onMissingHandler(Consumer<Exception> onMissingHandler); static final Consumer<Exception> IGNORE; static final Consumer<Exception> PRINT_STACK_TRACE; static final Consumer<Exception> RETHROW; }
@Test public void multimethodThrowingCall() throws Throwable { thrown.expect(BusinessException.class); HandlerOfManyEvents object = new HandlerOfManyEvents(); handler.call(object, new Destroyed(null)); }
@Test public void silentOnMissingCall() throws Throwable { HandlerOfManyEvents object = new HandlerOfManyEvents(); handler.call(object, new PaletteLabel("", "")); }
@Test public void multimethodPublicCall() throws Throwable { HandlerOfManyEvents object = new HandlerOfManyEvents(); handler.call(object, new Locked(null)); Assertions.assertThat(wasCalled).isTrue(); }
@Test public void multimethodProtectedCall() throws Throwable { HandlerOfManyEvents object = new HandlerOfManyEvents(); handler.call(object, new Delivered(null)); Assertions.assertThat(wasCalledProtected).isTrue(); }
@Test public void silentOnPrivateCall() throws Throwable { HandlerOfManyEvents object = new HandlerOfManyEvents(); handler.call(object, new Unlocked(null, 0, 0)); }