Hi,
I have a 6.10 project, and upgrading to 7.0.5.
However the lambda functions I have (see example below) are in red and I’m having to convert them to non-lambda functions - is this correct?
jobStatusField.addValueChangeListener(e -> {
getItem().setStatus((String)e.getValue());
});
and I’m having to change it to
jobStatusField.addValueChangeListener(new Consumer<com.haulmont.cuba.gui.components.HasValue.ValueChangeEvent>() {
@Override
public void accept(com.haulmont.cuba.gui.components.HasValue.ValueChangeEvent e) {
getItem().setStatus((String)e.getValue());
}
});
artamonov
(Yuriy Artamonov)
#2
Hi,
Since 7.0 you have to specify type of the value for a Component, e.g.:
@Inject
private LookupField<JobStatus> jobStatusField;
@Inject
private TextField<String> valueField;
You can easily do this for the entire screen in IntelliJ IDEA:
- Set cursor on a field without type that is highlighted with inspection (yellow background)
- Trigger Alt-Enter shortcut
- Select
Change field type to
- Use right arrow key and apply
Fix all in the file
option
See also Release notes.
So, you do not need to change your lambdas back to classes. Due to Java type erasure you only need to specify a correct type for the variable.
Once you’ve set correct types your code can be simplified, slightly:
jobStatusField.addValueChangeListener(e -> {
getItem().setStatus(e.getValue());
});
No need to cast value of the event anymore.
1 Like