Hi, I am in V14 environment with IntelliJ. I have a class definition like:
public class MyEditor < V > extends FlexLayout {
private Set< ComponentEventListener< MyEditorEvent<V> > > myListeners;
.....
private initHandler() {
ComponentUtil.addListener( this , MyEditorEvent.class , ( e ) -> {
.....
myListeners.forEach( ( listener ) -> listener.onComponentEvent( e ) );
.....
} );
}
.....
public static class MyEditorEvent < V > extends ComponentEvent< MyEditor< V > > {
public MyEditorEvent( MyEditor source , boolean fromClient ) {
super( source , fromClient );
}
}
}
The problem is, when compiling, the compiler kept showing error at the ComponentUtil.addListener with:
incompatible types: cannot infer type-variable(s) T
(argument mismatch; cannot infer functional interface descriptor for com.vaadin.flow.component.ComponentEventListener<com.company.ui.editor.MyEditor.MyEditorEvent>)
If I removed type parameter, all went well, but I can’t use type conversion within the class to send right type response. Any idea How I can use type with this class?
I have the same problem.
My project compiles successfully but in my colleague’s IDE the above error keeps showing during compilation.
public static abstract class GridEvent extends ComponentEvent<MyGrid<?>> {
protected GridEvent(MyGrid<?> source) {
super(source, false);
}
}
public static class DeleteEvent<T> extends GridEvent {
private static final long serialVersionUID = -3879145006704815249L;
private T t;
public DeleteEvent(MyGrid<?> source, T t) {
super(source);
this.t = t;
}
public T getT() {
return t;
}
}
public static class ItemClickEvent<T> extends GridEvent {
private static final long serialVersionUID = -3879145006704815249L;
private T t;
public ItemClickEvent(MyGrid<?> source, T t) {
super(source);
this.t = t;
}
public T getT() {
return t;
}
}
public <S extends ComponentEvent<?>> Registration addCustomListener(Class<S> eventType,
ComponentEventListener<S> listener) {
return getEventBus().addListener(eventType, listener);
}