What '???' in Scala?

I am studying Scalausing the IntelliJIDE.

When I subs class Elementand overrides the method contents, the IDE provided a default implementation for the method contentswith the definition???

Below is the code from the book Programming in Scala, 3rd edition

Element

abstract class Element {
  def contents: Array[String]

  def height = contents.length

  def width = if (height == 0) 0 else contents(0).length
}

Arrayelement

class ArrayElement(cont: Array[String]) extends Element {
  override def contents: Array[String] = ??? // impl provided by IDE
}

I do not see any problems when starting the program, but when I get access to the method I get below the exception

Exception in thread "main" scala.NotImplementedError: an implementation is missing
    at scala.Predef$.$qmark$qmark$qmark(Predef.scala:284)
    at org.saravana.scala.ArrayElement.contents(ScalaTest.scala:65)

Can someone explain what is ???and use it?

+4
source share
1 answer

???created as a placeholder and is a method defined in Predef(which is automatically imported by default)

This definition

def ??? : Nothing = throw new NotImplementedError

, Nothing, , , throw NotImplementedError. , , , .

Nothing - , ??? , .

+8

Source: https://habr.com/ru/post/1690445/


All Articles