For the following HwLogger.PersisterType enumeration:
object HwLogger extends Serializable {
object PersisterType extends Enumeration {
type Persisters = Value
val FilePersister, HdfsPersister, SocketPersister = Value
}
}
In the companion class - how do we access it? Notice the slew of imports below ..
class HwLogger extends Serializable {
import collection.mutable.ArrayBuffer
import HwLogger.PersisterType._
import HwLogger.PersisterType
var persisterTypes = ArrayBuffer[PersisterType]() // Compiler says " error: not found: type PersisterType"
def setDefaults : Unit = {
import PersisterType._
persisterTypes ++ FilePersister ++ HdfsPersister
}
}
UPDATE After the accepted answer (and syntax correction on the arraybuffer append operators) here is the corrected code:
object HwLogger extends Serializable {
object PersisterType extends Enumeration {
type Persisters = Value
val FilePersister, HdfsPersister, SocketPersister = Value
}
}
class HwLogger extends Serializable {
import collection.mutable.ArrayBuffer
import HwLogger.PersisterType._
import HwLogger.PersisterType
var persisterTypes = ArrayBuffer[Persisters]() // This is the fix (Persisters instead of PersisterType)
def setDefaults : Unit = {
import PersisterType._
persisterTypes :+ FilePersister :+ HdfsPersister
}
}
** Another update **
Changing the enumeration object will avoid the hassles:
object HwLogger extends Serializable {
object PersisterType extends Enumeration {
type PersisterType = Value // Changed the "type" to be same as object name
val FilePersister, HdfsPersister, SocketPersister = Value
}
}
class HwLogger extends Serializable {
import collection.mutable.ArrayBuffer
import HwLogger.PersisterType._
import HwLogger.PersisterType
var persisterTypes = ArrayBuffer[PersisterType]() // Revert back to PersisterType
def setDefaults : Unit = {
import PersisterType._
persisterTypes :+ FilePersister :+ HdfsPersister
}
}