This page is no longer maintained — Please continue to the home page at

Keywords in Scala standard library

No replies
Tomáš Heřman
Joined: 2011-09-28,
User offline. Last seen 42 years 45 weeks ago.
Hey guys,I just had this idea when writing a little project using scalatra and it's Map[String,AnyRef] based session. I tend to have a lot of typos when using string keys so i wrote myself this mini library:
  abstract class keyword {val str = this.getClass.getName} //to hopefully made sure that every class extending keyword has unique str value  implicit def keyword2string(kw: keyword) = kw.str
  object errors extends keyword  object notices extends keyword  Now i can use the objects like so    def appendError(error: String) = {session(err) = session.getOrElse(err,Vector[String]()).asInstanceOf[Vector[String]] :+ (error)}
So i was wondering if any of you think it may be a good idea to have this kind of abstract class and implicit in standard library. I think it would be useful, especially when dealing with Java systems that use a lot of String maps etc to have more compile-time erros and less 'where the eff did i made the typo'. Or is it just not worth adding? I know i could probably just use enum, but i find this a bit more clear.

Thanks for your opinions.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland