Infix operators do NOT work if an object has a method that takes two parameters:
Here's how to create a prefix operator for our own class.
Here's how to create a prefix operator for our own class. The only identifiers that can be used as prefix operators are +
, -
, !
, and ~
:
Any method which does not require a parameter can be used as a postfix operator: a.m
can be written as a m
.
Any method which does not require a parameter can be used as a postfix operator: a.m
can be written as a m
.
For instance, a.+(b)
is equivalent to a + b
and a.!
is the same as a!
.
Postfix operators have lower precedence than infix operators, so:
foo bar baz
means foo.bar(baz)
.foo bar baz bam
means (foo.bar(baz)).bam
foo bar baz bam bim
means (foo.bar(baz)).bam(bim)
.
Any method which takes a single parameter can be used as an infix operator: a.m(b)
can also be written as a m b
.
Prefix operators work if an object has a method name that starts with unary_
:
The parameterless execute method has been deprecated and will be removed in a future version of ScalaTest. Please invoke execute with empty parens instead: execute().
The trap method is no longer needed for demos in the REPL, which now abreviates stack traces, and will be removed in a future version of ScalaTest