How to check for null in a single statement in scala?

前端 未结 4 996
轻奢々
轻奢々 2020-12-23 09:28

In my scala code:

QueueManager.add(getObject)

where getObject is a method that returns an object of type QueueObject

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 09:57

    If it instead returned Option[QueueObject] you could use a construct like getObject.foreach { QueueManager.add }. You can wrap it right inline with Option(getObject).foreach ... because Option[QueueObject](null) is None.

提交回复
热议问题