Convert Scala condition to Java predicate

Cassie :

I am using the fabric8io Java library for working with Kubernetes in Scala. I would like to use waitUntilCondition function which received java.util.Predicate as the first argument. However, in Scala predicate is formed in a different form. And I get a compile error:

Type mismatch, expected: Predicate[Pod], actual: Nothing => Any

How can I define this predicate in Scala? Here is the code I used:

client.pods()
    .inNamespace("default")
    .withName("app-driver")
    .waitUntilCondition(condition => condition.getStatus().getPhase().equals("Running"), 15, TimeUnit.MINUTES)
Mario Galic :

Scala 2.12 seems to compile fine out of the box on my machine, however in Scala 2.11 I had to use scala-java8-compat asJavaPredicate as suggested by @KrzysztofAtlasik (just type ascription did not work for me).

If upgrading to Scala 2.12 or importing scala-java8-compat are not an option, then try instantiating Predicate[Pod] and override test method like so

waitUntilCondition(
  new Predicate[Pod] { def test(pod: Pod): Boolean = pod.getStatus.getPhase.equals("Running") }, 
  15, 
  TimeUnit.MINUTES
)

Guess you like

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