“???”是什么意思在 Scala lang 中代表什么?

问题描述

实际上,我有几个关于此代码片段的问题:

  1. '???'导致这个异常?
  2. 可以指定什么来代替“???” ?
  3. '???' 是什么意思代表什么?
object InfixTypesHard2 extends App {
  val x0: Int --- String --- Boolean = ???
}
    
class ---[T,V](t: T,v: V)

堆栈跟踪:

Exception in thread "main" scala.NotImplementedError: an implementation is missing
    at scala.Predef$.$qmark$qmark$qmark(Predef.scala:344)
    at section3_OOP_operatorOverloading.InfixTypesHard2$.delayedEndpoint$section3_OOP_operatorOverloading$InfixTypesHard2$1(InfixTypesHard2.scala:5)
    at section3_OOP_operatorOverloading.InfixTypesHard2$delayedInit$body.apply(InfixTypesHard2.scala:3)
    at scala.Function0.apply$mcV$sp(Function0.scala:39)
    at scala.Function0.apply$mcV$sp$(Function0.scala:39)
    at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
    at scala.App.$anonfun$main$1(App.scala:76)
    at scala.App.$anonfun$main$1$adapted(App.scala:76)
    at scala.collection.IterableOnceOps.foreach(IterableOnce.scala:563)
    at scala.collection.IterableOnceOps.foreach$(IterableOnce.scala:561)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:919)
    at scala.App.main(App.scala:76)
    at scala.App.main$(App.scala:74)
    at section3_OOP_operatorOverloading.InfixTypesHard2$.main(InfixTypesHard2.scala:3)
    at section3_OOP_operatorOverloading.InfixTypesHard2.main(InfixTypesHard2.scala)

解决方法

只是一个 method in Predef 从语言的角度来看它没有什么特别之处。
作为 you can see,实现只是抛出一个 new NotImplementedError

该方法的想法是您可以将其用作“实现”任何方法的填充物,而花哨名称的想法是可以很容易地注意到它,因为这个想法是??? 的任何用法都应该是临时的,并且是固定的。

如果您想知道为什么它可以在任何地方使用,那是因为 ??? 本身属于 Nothing 类型;这是因为抛出异常的行为具有这种类型。由于 Nothing 是所有类型(也称为底部类型子类型,它由于Liskov,始终可以使用。

什么可以代替'???' ?

类型:Int --- String --- Boolean;这只是一个奇怪的元组重新实现。

// For example:
new ---(new ---(1,"text"),false)
// Thanks to Jasper Moeys for providing the right syntax.

我猜这是一些家庭作业,不知道你被要求在这里做什么。
或者,该代码段的整个想法是表明当类型有两个类型参数时,您可以将类型用作中缀。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...