我通常最终尝试每个组合,直到它编译.有人可以解释我应该在哪里使用?
假设我有以下java方法
protected void onEvent(Object obj) {
}
Run Code Online (Sandbox Code Playgroud)
Scala编译器接受
protected override def onEvent(event: Any)
Run Code Online (Sandbox Code Playgroud)
和
protected override def onEvent(event: Object)
Run Code Online (Sandbox Code Playgroud)
这两者有什么区别吗?
拥有以下代码:log.info("parameters {}和{}",param1,param2)在Scala中编译并与SLF4J一起使用
但是如果我想传递更多参数,我需要使用Array:
log.info("parameters {} and {} and {}", Array(param1, param2,param3))
Run Code Online (Sandbox Code Playgroud)
它只是用array.toString替换第一个参数,并使其余参数保持未绑定状态.
以下代码
log.info("parameters {} and {} and {}", Array(param1, param2,param3) : _*)
Run Code Online (Sandbox Code Playgroud)
不编译,因为:
error: overloaded method value info with alternatives:
(org.slf4j.Marker,java.lang.String)Unit <and>
(java.lang.String,java.lang.Throwable)Unit <and>
(java.lang.String,Array[java.lang.Object])Unit <and>
(java.lang.String,Any)Unit
cannot be applied to (java.lang.String, Any)
log.info("parameters {} and {} and {}", Array(param1, param2,param3) : _*)
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
基于activator-akka-cassandra示例,我正在创建自己的应用程序,将数据保存到cassandra中.
我将数据模型定义如下
import play.api.libs.json.Json
case class Location(lat: Double, long: Double)
object Location {
implicit def toLocation(lat: Double, long: Double) = Location(lat, long)
}
case class LocationWithTime(location: Location, time: Long)
object LocationWithTime {
implicit def toLocationWithTime(location: Location, time: Long) = LocationWithTime(location, time)
}
case class Ping(pingUuid: String, senPhoneNumber: String, recPhoneNumber: Set[String], locationWithTime: LocationWithTime)
object Ping {
implicit val LocationFormat = Json.format[Location]
implicit val LocationWithTimeFormat = Json.format[LocationWithTime]
implicit val PingFormat = Json.format[Ping]
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,应该保存数据的代码:
def insertPing(ping: Ping): Unit =
session.executeAsync(insertPing.bind(ping.pingUuid, …Run Code Online (Sandbox Code Playgroud)