Why is the `unary_` prefix needed in scala?

后端 未结 2 1695
暗喜
暗喜 2021-01-30 22:31

Beginner Scala question, but I couldn\'t find the answer on here.

Similar to overloading in C++, I would expect the compiler can tell the difference between a method cal

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 23:01

    Because in scala it is totally fine to create a method named -, that takes no arguments. How would you distinguish between a normal and a unary method? For example ! has a totally different meaning as unary, than as post fix operator.

提交回复
热议问题