[英]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.