我有一個序列爲:斯卡拉序列[類型]錯誤時,模式匹配
def myMethod(mySeq: Seq[SomeType]) = mySeq match {
case Nil => // do someting
case _ => // do something else (error happens here)
}
當我運行這段代碼,我得到以下錯誤:
a type was inferred to be `Any`; this may indicate a programming error
我從來沒有見過這個錯誤迄今。我在Scala 2.11上。我對這個錯誤是什麼感到無能爲力?任何線索?
編輯:這是我所受到質疑的實際方法:
def publishMessages(mySeq: Seq[MyData]): Future[Continue] = Future {
if (mySeq.nonEmpty) {
logger.info(s"sending a total of ${mySeq.length} for " +
s"metric ${mySeq.head.metric} messages to kafka topic ${producerConfig.topic}")
val jsonMessage = Json.stringify(Json.toJson(mySeq))
val recordMetaDataF = Future {
scala.concurrent.blocking {
val recordMetaDataJavaFut = producer.send(
new ProducerRecord[String, String](producerConfig.topic, jsonMessage)
)
// if we don't make it to Kafka within 3 seconds, we timeout
recordMetaDataJavaFut.get(3, TimeUnit.SECONDS)
}
}
recordMetaDataF.recover {
case NonFatal(ex) =>
logger.error("Exception while persisting data-points to kafka", ex)
}
Continue
}
else {
logger.debug(s"skip persisting to kafka topic ${producerConfig.topic} as no " +
" data-points were given to persist")
Continue
}
}
這是我看到的時候我編譯警告:
[warn] Scala version was updated by one of library dependencies:
[warn] * org.scala-lang:scala-library:(2.11.1, 2.11.7, 2.11.2, 2.11.6, 2.11.5, 2.11.0) -> 2.11.8
[warn] To force scalaVersion, add the following:
[warn] ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
[warn] Run 'evicted' to see detailed eviction warnings
我仍然得到這個錯誤:
a type was inferred to be `Any`; this may indicate a programming error
你正在嘗試做什麼? –
爲什麼這很重要?這兩個路徑都返回一個正確的和相同的類型。 IntelliJ不會抱怨這種方法! – sparkr
因爲您發佈的代碼不需要用空白評論推斷任何內容,所以它不會產生任何錯誤。 –