简体   繁体   中英

How scala implicit make abstract method valid parameter so I can use method in java

So this is a bit of a strange question, but I am trying to make use of a piece of code that is in scala and takes a set of parameters. In scala the parameters are implicits so scala is able to do its magic to fill in what those objects need. But since I can't make an abstract object be "implicit" in java, I need to figure out how to create the object, but can't for the life of me.

Here is the scala code:

class AsyncSchemaRegistryClient (
  val baseUri: String
) (
  implicit as: ActorSystem,
  m: Materializer,
  ec: ExecutionContext
) extends SchemaRegistryClient[Future] with Json4sSupport {...

So this is called by another method in original code (in a long twisty path of Guice Inject and sub modules that is hard enough to follow as is), and I am trying to call it in the java code like this:

private AsyncSchemaRegistryClient asyncSchemaRegistryClient = new AsyncSchemaRegistryClient("test", ActorSystem.create(), Materializer(), new ExecutionContext);

Now the ActorSystem.create() seems to be valid (at least the compiler isn't yelling about it), but the Materializer and the ExecutionContext I cannot initialize because the are abstract. Also it is worth saying that the Materializer is akka.stream.Materializer and ExecutionContext is scala.concurrent.ExecutionContext.

The reason I am trying to make use of this AsyncSchemaRegistryClient is that it has a lot of code already set up for properly calling a schema registry and handling if it comes back with valid schema data or not and seems to be the easiest way to implement async checks on schema in my program.

Thanks in advance for any and all advice!

Try

ActorSystem system = ActorSystem.create();
ExecutionContextExecutor ec = system.dispatcher();
ActorMaterializer mat = ActorMaterializer.create(system);

new AsyncSchemaRegistryClient("test", system, mat, ec);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM