What does '???' (three question marks) mean in Scala?

Scala FAQ: What does the use of three questions marks (???) in Scala mean?

The syntax of using three question marks in Scala lets you write a not-yet implemented method, like this:

def createWorldPeace = ???

The methods you define can also take input parameters and specify a return type, like this:

def doSomething(s: String): Int = ???

Usefulness of `???`

This three question mark approach is really nice for when you want to stub out some methods as you’re working on a problem. For instance, you might be working on an IoT application to control a garage door, and you know you’re going to need methods to open and close the door, but you don’t know the details yet. In this case you can stub out your methods like this:

def openGarageDoor = ???
def closeGarageDoor = ???

Martin Odersky’s original post about ???, and an interesting discussion

In this funny and interesting post on the scala-lang.org website, Martin Odersky writes, “If people don’t hold me back I’m going to add this to Predef,” which he later did. Here’s a link to the current Predef source code, which shows the ??? method is defined like this:

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

Note: If you’ve never seen a discussion about adding a new feature to a programming lanuage, check out that funny/interesting link. People suggest using TODO or ToDo instead of ???, but Mr. Odersky decides to go with ??? in the end. (He also notes that he wants to use the ??? syntax in training classes.)

If you ever wondered what ??? meant in Scala, I hope this is helpful.

Add new comment

Anonymous format

  • Allowed HTML tags: <em> <strong> <cite> <code> <ul type> <ol start type> <li> <pre>
  • Lines and paragraphs break automatically.