Scala – Pattern matching always match first object

In a scala program, I had some code like

def remove(something: Any): Unit = {
  something match {
    case signature => ...
    case tls => ...
    case host => ...
    case port => ...
    case password => ...
    case _ => ...
  }
}

Where signature, tls, host, port, password were all objects defined like

object host

But when calling this method, passing an object, it always matched the first case “signature”.

The solution is to replace the objects in the cases with `object`

def remove(something: Any): Unit = {
  something match {
    case `signature` => ...
    case `tls` => ...
    case `host` => ...
    case `port` => ...
    case `password` => ...
    case _ => ...
  }
}

The solution comes from http://www.scala-lang.org/old/node/5223