相关疑难解决方法(0)

Any,AnyVal,AnyRef,Object之间的关系是什么?它们在Java代码中使用时如何映射?

我通常最终尝试每个组合,直到它编译.有人可以解释我应该在哪里使用?

scala

108
推荐指数
3
解决办法
3万
查看次数

在Scala中,Any和Object有什么区别?

假设我有以下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)

这两者有什么区别吗?

scala

36
推荐指数
2
解决办法
9487
查看次数

Scala和SLF4J ::传递多个参数

拥有以下代码: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)

我在这里错过了什么?

scala variadic-functions slf4j

6
推荐指数
2
解决办法
3212
查看次数

自动映射和"隐式转换必须比Any Ref更具体"错误

基于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)

scala

3
推荐指数
1
解决办法
2087
查看次数

标签 统计

scala ×4

slf4j ×1

variadic-functions ×1