Scala - Enumeration vs. Case-Classes

Posted by tzofia on Stack Overflow See other posts from Stack Overflow or by tzofia
Published on 2012-11-12T12:12:20Z Indexed on 2012/11/12 17:00 UTC
Read the original article Hit count: 319

Filed under:
|
|
|
|

I've created akka actor called LogActor. The LogActors's receive method handling messages from other actors and logging them to the specified log level.

I can distinguish between the different levels in 2 ways. The first one:

import LogLevel._
object LogLevel extends Enumeration {
    type LogLevel = Value
    val Error, Warning, Info, Debug = Value
}
case class LogMessage(level : LogLevel, msg : String) 

The second: (EDIT)

abstract class LogMessage(msg : String)
case class LogMessageError(msg : String) extends LogMessage(msg)
case class LogMessageWarning(msg : String) extends LogMessage(msg)
case class LogMessageInfo(msg : String) extends LogMessage(msg)
case class LogMessageDebug(msg : String) extends LogMessage(msg)

Which way is more efficient? does it take less time to match case class or to match enum value?

(I read this question but there isn't any answer referring to the runtime issue)

© Stack Overflow or respective owner

Related posts about scala

Related posts about enums