我正在设置Client的连接超时,如
def newClient(host: String): Client = asyncHttpClient match {
case true => {
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
AhcHttpClient.create()
}
case _ => {
import com.sun.jersey.api.client.Client
val client: Client = Client.create()
client.setConnectTimeout(5000)
//Or client.setConnectTimeout(Int.box(5000))
}
}
并收到错误消息
类型单位的表达式未确认预期类型客户端
有人可以帮助理解问题并正确传递整数值吗?
答案 0 :(得分:4)
声明您的方法返回类型为Client
的值。 client.setConnectionTimeout
的返回类型为Unit
,而不是Client
,因此您无法从方法中返回该类型。相反,您应该返回client
:
def newClient(host: String): Client = asyncHttpClient match {
case true => {
import org.sonatype.spice.jersey.client.ahc.AhcHttpClient
AhcHttpClient.create()
}
case _ => {
import com.sun.jersey.api.client.Client
val client: Client = Client.create()
client.setConnectTimeout(5000)
client
}
}