user51
user51

Reputation: 10143

How to return Scala `Unit` type in java function

I've a twitter future and I want to implement onFailure callback for this.

The type signature for onFailure is def onFailure(fn: Throwable => Unit): Future[A].

Below is the sample code from my project:

import com.twitter.util.Future

Future f = getTwitterFuture()
f.onFailure(ex -> {
  //business Logic here 
  return; //Not sure how to return scala unit from java
});

In the above code if I do return;, I get error Missing return Value. If I do return void, I get ; expected error.

I've below scala and java SDK in my project.

Scala version - 2.12.6 Java version - java version "1.8.0_144"

I know scala 2.12.6 binary interoperability works well in java 8. But I don't know how to write this.

Upvotes: 3

Views: 661

Answers (1)

ghik
ghik

Reputation: 10764

That would be

return scala.runtime.BoxedUnit.UNIT;

Upvotes: 3

Related Questions