Gary Sieling

???: Scala triple question mark operator

Scala has a neat, but un-googleable operator called “???”. If this looks like a placeholder, that’s because it is: this is a method which does nothing but throw NotImplementedException.

You can use it like so:

val n = e.nextElement match {
  case e: NetworkInterface => e
  case _ => ???
} 

This is a great tool: for instance, if you are building a tool that processes data that is scraped, or from an API you don’t control, you can use this to handle code branches that you haven’t and aren’t sure how to handle.

This operator is defined on the “Predef” object, which by default is pulled into the global scope of your code.


  /** `???` can be used for marking methods that remain to be implemented.
   *  @throws NotImplementedError
   */
  def ??? : Nothing = throw new NotImplementedError

Exit mobile version