鉴于此Java:
Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
Map<String, Object> arguments) throws IOException;
从Scala传递null
这样的法律是合法的:
channel.queueDeclare(inputQueueName, true, false, true, null)
Scala中传递空映射的声明是什么?这样:
channel.queueDeclare(inputQueueName, true, false, true, Map[String, Object]())
结果:
found : scala.collection.immutable.Map[String,Object]
required: java.util.Map[String,Object]
channel.queueDeclare(inputQueueName, true, false, true, Map[String,Object]())
和
channel.queueDeclare(inputQueueName, true, false, true, java.util.HashMap[String,Object]())
结果:
object java.util.HashMap is not a value
答案 0 :(得分:3)
import scala.collection.JavaConverters._
val emptyMap = Map.empty[String, Object].asJava
// java.util.Map[String, Object]
channel.queueDeclare(inputQueueName, true, false, true, emptyMap)
或者:
channel.queueDeclare(inputQueueName, true, false, true, new java.util.HashMap[String, Object]())
// ^ add new here
new java.util.HashMap[String, Object]
(没有括号)也有效。