我有以下的類定義在斯卡拉:問題與Scala的構造函數和枚舉
class AppendErrorMessageCommand private(var m_type: Byte) {
def this() = this(0x00)
def this(errorType: ErrorType) = this(getErrorTypeValue(errorType))
private def getErrorTypeValue(errorType: ErrorType) = {
if(errorType == USER_OFFLINE)
0x01
else if(errorType == PM_TO_SELF)
0x02
0x00
}
}
錯誤類型是以下枚舉:
object ErrorType extends Enumeration {
type ErrorType = Value
val USER_OFFLINE, PM_TO_SELF = Value
}
我覺得有什麼不妥在類的構造函數定義。我的IDE(這是Eclipse的Scala IDE)告訴我它找不到getErrorTypeValue。它也告訴我,重載的構造函數有替代。一個是字節,另一個是枚舉。
儘管如此,不要把這些IDE的錯誤信息當回事。他們可能是錯的,因爲這經常發生在IDE中。但是,當IDE告訴我有什麼不對,通常是錯誤的。
那麼,我的類/構造函數定義有什麼問題?