16

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

7
  • how about stackoverflow.com/questions/37828790/… Commented Jul 30, 2019 at 7:02
  • Check out here stackoverflow.com/questions/16120697/… Commented Jul 30, 2019 at 7:07
  • @P.Juni The reference you gave has a callback that accept one argument, but I have a callback without any parameters. So that doesn't solve the problem. Commented Jul 30, 2019 at 7:10
  • 2
    @PrajeetShrestha please share the code before your showAdWithCallback Commented Jul 30, 2019 at 7:15
  • 1
    @BartekLipinski. Oh u got me........I had return statement just before showAdWithCallback. I was randomly embedding showAdWithCallback to tryout, overlooked the return statement. Thank u so much. You can put it as a answer I will accept and upvote. Commented Jul 30, 2019 at 7:24

3 Answers 3

13

The error message is caused by the code before your:

showAdWithCallback(() -> {
        return null;
});
Sign up to request clarification or add additional context in comments.

Comments

1

Call kotlin object and call function

kotlinobject.INSTANCE.showAdWithCallback(()->{
    return null;
})

Comments

0

callback:() -> Unit

It's a typically runnable - zero arguments, without return value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.