我對Scala有點新鮮。以下是我的代碼。Scala警告匹配可能不完全
Option(Session.get().getAttribute("player")) match {
case None => {
val player = new Player(user.getEmail, user.getNickname).createOrGet
Session.get().setAttribute("player", player)
}
}
我編譯
Warning:(35, 11) match may not be exhaustive.
It would fail on the following input: Some(_)
Option(Session.get().getAttribute("player")) match {
^
我該如何解決這個問題時,得到下面的警告?有沒有辦法重寫代碼以避免警告?(我正在使用Scala版本2.10.2)
謝謝。我將使用你建議的 –
對於樣式,我會'Session.get.getAttr (「foo」)匹配{case null => case _ =>}。更容易閱讀或者選擇(...)或者else alt或者Some(Session.get)過濾器(_.getAttr(「foo 「)!= null)orElse(s => Some(s.setAttr(」「,x)))''或類似的。 –