![](/img/trans.png)
[英]Can I define an abstract method without the use of abstract keyword in Java?
[英]How scala implicit make abstract method valid parameter so I can use method in java
因此,这是一个奇怪的问题,但是我正在尝试利用scala中的一段代码并采用一组参数。 在scala中,参数是隐式的,因此scala可以发挥其魔力来填充那些对象所需的内容。 但是,由于我无法使抽象对象在Java中成为“隐式”,因此我需要弄清楚如何创建该对象,但是这对我来说是一辈子的。
这是scala代码:
class AsyncSchemaRegistryClient (
val baseUri: String
) (
implicit as: ActorSystem,
m: Materializer,
ec: ExecutionContext
) extends SchemaRegistryClient[Future] with Json4sSupport {...
因此,这是由原始代码中的另一种方法调用的(在Guice Inject和子模块的较长曲折路径中,很难按原样进行操作),我正在尝试像这样在Java代码中调用它:
private AsyncSchemaRegistryClient asyncSchemaRegistryClient = new AsyncSchemaRegistryClient("test", ActorSystem.create(), Materializer(), new ExecutionContext);
现在ActorSystem.create()似乎是有效的(至少编译器没有对此大喊大叫),但是我无法初始化Materializer和ExecutionContext,因为它们是抽象的。 同样值得一提的是,Materializer是akka.stream.Materializer和ExecutionContext是scala.concurrent.ExecutionContext。
我尝试使用此AsyncSchemaRegistryClient的原因是,它已经设置了很多代码,可以正确地调用架构注册表并处理是否返回有效的架构数据,这似乎是实现异步的最简单方法检查我程序中的架构。
在此先感谢您提供任何建议!
尝试
ActorSystem system = ActorSystem.create();
ExecutionContextExecutor ec = system.dispatcher();
ActorMaterializer mat = ActorMaterializer.create(system);
new AsyncSchemaRegistryClient("test", system, mat, ec);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.