我有 Java 多语言应用程序,它主要有 Java 代码,并且也使用很少的 Scala 库。
下面的 Scala 代码编译得很好。
import com.twitter.finagle.Http.Client
import com.twitter.finagle.Http
import com.twitter.finagle.param.Logger
object Main extends App {
private val loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger")
val client: Client = Http.client
.configured(Logger(loggerFinagle))
}
我在java中编写了如下相同的代码
import com.twitter.finagle.Http;
import com.twitter.finagle.param.Logger;
public class JavaMain {
public static void main(String[] args) {
java.util.logging.Logger loggerFinagle = java.util.logging.Logger.getLogger("FinagleLogger");
Http.client()
.configured(new Logger(loggerFinagle));
}
}
当我编译代码时,出现以下错误 -
[info] Compiling 1 Scala source and 1 Java source to /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/target/scala-2.12/classes ...
[error] /Users/rajkumar.natarajan/Documents/Coding/finagle-errors/src/main/java/JavaMain.java:10:1: no suitable method found for configured(com.twitter.finagle.param.Logger)
[error] method com.twitter.finagle.Stack.Parameterized.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (actual and formal argument lists differ in length))
[error] method com.twitter.finagle.Stack.Parameterized.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] method com.twitter.finagle.client.StackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (actual and formal argument lists differ in length))
[error] method com.twitter.finagle.client.StackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] method com.twitter.finagle.client.EndpointerStackClient.<P>configured(P,com.twitter.finagle.Stack.Param<P>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (actual and formal argument lists differ in length))
[error] method com.twitter.finagle.client.EndpointerStackClient.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] method com.twitter.finagle.Http.Client.<P>configured(scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>) is not applicable
[error] (cannot infer type-variable(s) P
[error] (argument mismatch; com.twitter.finagle.param.Logger cannot be converted to scala.Tuple2<P,com.twitter.finagle.Stack.Param<P>>))
[error] Http.client()
[error] .configured
看起来我必须通过元组,但我不知道如何。
github中的项目在这里。
以下是我的项目的依赖项详细信息 -
斯卡拉版本 - 2.12.6
Java 版本 - 1.8.0_151
最终版本 - 7.1.0