Which are the rules that make an Interface capable of being used as trailing lambda argument?
I though that the only rule was for it to be having a unique function on its definition, however I got myself into the following problem:
I had this Java interface
public interface ToolbarFragmentCallBack {
void onNavigationClick();
}
Called from a java class:
public void addToolBar(int container, String title, boolean isParent,
ToolbarFragment.ToolbarFragmentCallBack callback) {
//do something
}
Which was called from both Kotlin and Java files:
Kotlin (1):
addToolBar(R.id.toolbar_fragment, toolbarTitle, toolbarParent) {
presenter.onClickNavigationToolBar()
}
Java (2):
addToolBar(R.id.toolbar_fragment, definition.getTitle(), false, () -> {
activity.onBackPressed();
});
However, I recently migrated the interface to Kotlin:
interface ToolbarFragmentCallBack {
fun onNavigationClick()
}
And now the **Kotlin (1) ** implementation calls don't compile, with message
Type mismatch: inferred type is () -> Unit but ToolbarFragment.ToolbarFragmentCallBack! was expected