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.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值