Passing Function0 <boolean> from Java to Scala

I have a scala file with the following function:

def whitelist(shouldSample: => Boolean = true)


Now, in Java code, I would like to pass Function0 as an argument:

Function0<Boolean> filterFunction = new AbstractFunction0<Boolean>() {
  public Boolean apply() {
    return true;



Intellij complains that it is filterFunction

not parameterized by a Java primitive boolean

, which I cannot do as it is a primitive. The compiler also complains, asking to filterFunction

be parameterized java.lang.Object

. Using Object

boolean instead works for the compiler, but Intellij is still complaining. scala.Boolean

doesn't work as I thought Java would boolean

automatically convert to scala primitives boolean


The usage Object

seems very strange to me. Is there a better practice for this?


source to share

All Articles