Three Question Marks in Scala

Suraj P Jan 24, 2022
Three Question Marks in Scala

Scala’s three question marks ??? are defined in predef, designed as a placeholder. These question marks help us in writing methods that are not yet implemented.

Example one:

def testMethod = ???

Example two:

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

The three-question marks approach is really helpful when sketching some methods when working on some projects.

For example, we are developing an AI application that reads the image gives its description, and we know we are going to need methods to read the image and display its details, but we don’t know the details yet.

So, in this case, we can stub out our methods like this:

def readImage = ???
def printDescription = ???

The ??? has a return type nothing. It allows us to use placeholder implementation for the methods we have defined but didn’t implement yet but still want the compiler to compile the code.

Author: Suraj P
Suraj P avatar Suraj P avatar

A technophile and a Big Data developer by passion. Loves developing advance C++ and Java applications in free time works as SME at Chegg where I help students with there doubts and assignments in the field of Computer Science.

LinkedIn GitHub

Related Article - Scala Methods