I can define a bang operator method, but I cannot name it in Scala. What for?
First, I define a method !
:
scala> def !() = "hi"
$bang: ()java.lang.String
Now I can call it like this:
scala> $bang()
res3: java.lang.String = hi
But this doesn't work:
scala> !()
<console>:8: error: value unary_! is not a member of Unit
!()
Even this doesn't work:
scala> `!`()
<console>:8: error: value unary_! is not a member of Unit
`!`()
^
What am I doing wrong here? Why can I detect !()
when I cannot call it?
EDIT1
Adding an object reference gives an error:
scala> this.!()
<console>:8: error: value ! is not a member of object $iw
this.!()
^
+3
source to share