2014-05-24 88 views
0

我想返回一個名爲Entry的案例類,所以我不能更改函數的簽名。當我充滿了我的情況下類,並試圖返回它,我得到以下錯誤:scala返回案例類別不匹配

<console>:13: error: type mismatch; 
found : Entry(in method apply) 
required: <empty>.Entry 

我不知道爲什麼功能要求該類型

def apply(line: String) : Entry = { 
    case class Entry(account:String, password:String, UID:Int, GID:Int, 
        GECOS:String, directory:String, shell:String) 
    val fields = line.split(":") 
    val x = Entry(fields(0), fields(1), fields(2).toInt, fields(3).toInt, 
     fields(4), fields(5), fields(6)) 
    x 
} 

回答

2

這是一個猜測,但我相信Entry在其他地方定義。我這樣說是因爲你在函數簽名中引用了「Entry」類,但是你也在函數體中定義了一個case類。您要返回的Entry不是函數期望的Entry

+0

謝謝,這是問題所在。 – Sugihara