EventListener for template class

Hello everyone,
I try to create a generic class with grid (see code below). Now the method addEditListener gives me an error cause I don’t get the arguments for addListener right. I simply just got stuck on getting https://vaadin.com/docs/v14/flow/creating-components/tutorial-component-events to work with such a class type. For my SimpleEditTable I want the events also to be handled here and not in every subclass.

Thank you in advance.

public class SimpleEditTable<T> extends Div {
    ...
    // components etc.
    ...

    /**
     * Custom event class with connection to the vaadin component event system.
     */
    public abstract class SimpleEditTableEvent extends ComponentEvent<SimpleEditTable<T>> {

        private T entity;

        protected SimpleEditTableEvent(SimpleEditTable<T> source, T entity) {
            super(source, false);
            this.entity = entity;
        }

        public T getEntity() {
            return this.entity;
        }

    }

    /**
     * Edit event listener.
     */
    public class EditEvent extends SimpleEditTableEvent {

        EditEvent(SimpleEditTable<T> source, T entity) {
            super(source, entity);
        }

    }

    /**
     * Add component listener to the grid events.
     * @param eventType
     * @param listener
     * @return
     * @param <U>
     */
    public Registration addEditListener(ComponentEventListener<EditEvent> listener) {
        return addListener(EditEvent.class, listener);
    }
}

I tried it that way:

/**
     * Custom event class with connection to the vaadin component event system.
     */
    public static abstract class SimpleEditTableEvent<U> extends ComponentEvent<SimpleEditTable<U>> {

        private U entity;

        protected SimpleEditTableEvent(SimpleEditTable<U> source, U entity) {
            super(source, false);
            this.entity = entity;
        }

        public U getEntity() {
            return this.entity;
        }

    }

    /**
     * Edit event listener.
     */
    public static class EditEvent<U> extends SimpleEditTableEvent<U> {

        EditEvent(SimpleEditTable<U> source, U entity) {
            super(source, entity);
        }

    }

    /**
     * Add component listener to the grid events.
     * @param eventType
     * @param listener
     * @return
     * @param <U>
     */
    public <U extends ComponentEvent<?>> Registration addListener(Class<U> cls, ComponentEventListener<U> listener) {
        return addListener(cls, listener);
    }

But now when I want to register a method I cannot figure out the right method with argument to recieve the event:

    private void gridEditEmployee(EmployeeGrid.EditEvent<?> event) {
        //employeeEditDialog.open(event.get());
    }

I always get:

incompatible type - function interface descriptor cannot be derived

It seem to be the same problem as described here: https://vaadin.com/forum/thread/17903093/problems-to-use-componenteventlistener

Cause it seems, for now, no one has an idea I solved it by making the event classes independent from the parametrized type by just wanting it to be derived from abstractentity. The downside is, that an additional cast has to be done in order to get the right object in the listener.

Does this work?

public <U extends SimpleEditTableEvent<T>> Registration addListener(Class<U> cls, ComponentEventListener<U> listener) {
    return addListener(cls, listener);
}
private void gridEditEmployee(SimpleEditTable.EditEvent<Employee> event) {
    //employeeEditDialog.open(event.getEntity());
}
employeeGrid.addListener(SimpleEditTable.EditEvent.class, this::gridEditEmployee);

// Or using a lambda expression
employeeGrid.addListener(SimpleEditTable.EditEvent.class, event -> gridEditEmployee(event));