I have a method with generic parameters:
public static void addActionColumnAndSetSelectionListener(Grid<? extends UpdatableRecord<?>> grid,
EditDialog<? extends UpdatableRecord<?>> dialog,
Callback afterSave, Supplier<UpdatableRecord<?>> onNewRecord,
Consumer<? extends UpdatableRecord<?>> insteadOfDelete) {
Button buttonAdd = new Button(grid.getTranslation("Add"));
buttonAdd.addClickListener(event -> dialog.open(onNewRecord.get(), afterSave));
grid.addComponentColumn(record -> {
Button delete = new Button(grid.getTranslation("Delete"));
delete.addThemeVariants(ButtonVariant.LUMO_ERROR);
delete.addClickListener(event -> {
getBean(TransactionTemplate.class).executeWithoutResult(transactionStatus -> {
try {
if (insteadOfDelete != null) {
insteadOfDelete.accept(record);
} else {
getBean(DSLContext.class).attach(record);
}
record.delete();
} catch (DataAccessException e) {
Notification.show(e.getMessage());
}
});
});
HorizontalLayout horizontalLayout = new HorizontalLayout(delete);
horizontalLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.END);
return horizontalLayout;
}).setTextAlign(ColumnTextAlign.END).setHeader(buttonAdd);
grid.addSelectionListener(event -> event.getFirstSelectedItem().ifPresent(record -> dialog.open(record, afterSave)));
}
The problem is that the line insteadOfDelete.accept(record);
does not compile:
Error:(47, 52) java: incompatible types: org.jooq.UpdatableRecord<capture#1 of ?> cannot be converted to capture#2 of ? extends org.jooq.UpdatableRecord<?>
I don't understand the problem. If I change
Consumer<? extends UpdatableRecord<?>> insteadOfDelete
to
Consumer<UpdatableRecord<?>> insteadOfDelete
it compiles.