我有以下Scala代碼爲什麼我用下面的代碼得到'這個結構下面的死代碼'?
def message(attachmentId: UUID) : URI = {
var r : mutable.MutableList[BasicTemplate] = new mutable.MutableList[BasicTemplate]
val t : Type = new TypeToken[Iterable[BasicTemplate]](){}.getType()
val m : String = "[{\"basicTemplate\":\"TEMPLATE\",\"baseline\":\"DEMO\",\"identifier\":\"0599999999\"}]"
r = new Gson().fromJson(m, t)
Console.println(r.head.getBasicTemplateName)
URI.create("http://google.com")
}
而且它給了我下面的編譯錯誤:
[ERROR] Class1.scala:402: error: dead code following this construct
[ERROR] r = new Gson().fromJson(m, t)
任何想法,爲什麼我得到這個錯誤的高度讚賞!
您不需要在聲明變量後指定類型。 – wheaties
可能是由'r'重新分配造成的。更多信息 - https://issues.scala-lang.org/browse/SI-6339 – fiction
我不知道你的錯誤,但你創建了一行「var r ... = new ...」列表,然後你爲什麼你不使用val r = new Gson()... – Arne