以下代碼會產生四種類型不匹配錯誤。爲什麼?在第一和第二種情況下,我正在與Strings進行簡單的比較。在第三種情況下,我將false
分配給Boolean
類型的變量。在最後的情況下,我只是打印一個堆棧跟蹤!使用Scala中的Jedis類型不匹配
我很困惑。
的代碼:
//return TRUE if logged in
def isLoggedIn(auth: String): Boolean = {
val jedis = pool.getResource()
var userid = jedis.get("auth:" + auth)
var retVal = false
try {
if(userid != null) { //error here
val userAuth = jedis.get("uid:" + userid + ":auth")
if(userAuth == auth) { // error here
retVal = true // error here
}
}
} catch {
case e => e.printStackTrace() //error here
} finally {
pool.returnResource(jedis)
return retVal
}
}
錯誤:
[error] type mismatch;
[error] found : Unit
[error] required: Boolean
[error] retVal = true // error here
[error] ^
[error] type mismatch;
[error] found : Unit
[error] required: Boolean
[error] if(userAuth == auth) { // error here
[error] ^
[error] type mismatch;
[error] found : Unit
[error] required: Boolean
[error] if(userid != null) { //error here
[error] ^
[error] type mismatch;
[error] found : Unit
[error] required: Boolean
[error] case e => e.printStackTrace() //error here
[error] ^
[error] four errors found
我使用Jedis 2.0.0(https://github.com/xetorthio/jedis)與Redis的接口D B。 Jedis.get()方法返回String
。我正在使用sbt 0.10.1和scala 2.9.0-1。
發生了什麼事?
我們需要更多的上下文來幫助您弄清楚發生了什麼。例如,周圍的方法或表達式應該返回什麼?編譯器抱怨什麼行/列? –
對不起。我在錯誤中添加了更多代碼和詳細信息。謝謝。 – Raphael