How to pass function as parameter from java to kotlin method?

Prajeet Shrestha :

I have a Kotlin Code:

fun showAdWithCallback(callback:() -> Unit) {
    if (AdsPrefs.shouldShowInterstitialAd()) {
        mInterstitialAd.show()
        this.callback = callback
    } else {
        callback()
    }
}

Now I want to call this method from a Java Class. I am confused about how to call this. Here is what I tried

  showAdWithCallback(() -> {
        return null;
    });

But it shows following error.

enter image description here

Bartek Lipinski :

The error message is caused by the code before your:

showAdWithCallback(() -> {
        return null;
});

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=124718&siteId=1