I have code in java which wors pretty well:
public static void selectFirst(ComboBox combo) {
DataProvider dataProvider = combo.getDataProvider();
if (dataProvider != null) {
Optional comboValues = dataProvider.fetch(new Query<>()).findFirst();
if (comboValues.isPresent()) {
combo.setValue(comboValues.get());
}
}
}
I tried to convert to this method to kotlin and this is what IJ Idea generated
fun selectFirst(combo: ComboBox<*>) {
val dataProvider = combo.dataProvider
if (dataProvider != null) {
val comboValues = dataProvider.fetch(Query<Any, Any>()).findFirst()
if (comboValues.isPresent) {
combo.setValue(comboValues.get())
}
}
}
But it won’t compile. This is what compiler says:
Out-projected type 'DataProvider<out Any!, out Any!>!' prohibits the use of 'public abstract fun fetch(p0: Query<T!, F!>!): Stream<T!>! defined in com.vaadin.data.provider.DataProvider'
How can this kotlin code be fixed?
Or is there any other way of selecting first item in combobox which can be converted to kotlin?