Actually, I have several Qs regarding to this code snippet:
object InfixTypesHard2 extends App {
val x0: Int --- String --- Boolean = ???
}
class ---[T, V](t: T, v: V)
Stacktrace:
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)
Is just a method in Predef
nothing special about it from the language point of view.
As you can see the implementation is just throwing a new NotImplementedError
.
The idea of that method is that you can use it as a filler to "implement" any method, and the idea of the fancy name was that it could be noticed easily since the idea is that any usage of ???
should be temporary and fixed latter.
And if you wonder why it can be used in any place, it is because ???
itself is of type Nothing
; this because the act of throwing an exception has such type. And since Nothing
is the subtype of all types (also known as the bottom type) it can always be used due Liskov.
What could be assigned instead of '???' ?
Something of type: Int --- String --- Boolean
; which is just a weird tuple re-implementation.
// For example:
new ---(new ---(1, "text"), false)
// Thanks to Jasper Moeys for providing the right syntax.
I guess this is some homework, no idea what you were asked to do here.
Or maybe, the whole idea of the snippet is to show that you can use types as infix when they have two type parameters.