On Mon, 26 Jul 2010, Greg Brown wrote:

nobody likes defining anonymous classes

I like anonymous inner classes. They are great for defining internal event handlers.

Ahhh... I'm just referring to using a method instead of a class that defines a single method. My event listener interface looks like

public interface EventListener {
        public void invoke(Event e);
}

and my event listener factory looks like

static MethodEventListener create(Object target, String listenerMethodName) {
        final Method listenerMethod;

        try {
                Class<?> targetClass = target.getClass();
                listenerMethod = targetClass.getMethod(listenerMethodName, 
Event.class);
        } catch (RuntimeException ex) {
                throw ex;
        } catch (Exception ex) {
                throw new RuntimeException(ex);
        }

        return new MethodEventListener(target, listenerMethod);
}

Cheers,

Michael

Reply via email to