Method Name Convention

The feature you’re going to look at in this section is pretty cool (I really think so), but it’s also something that can be a bit hard to grasp. If an oxygen mask appears in front of you as you read these pages, secure your mask first before assisting your fellow programmers.

In Operator Overloading, you saw how Scala supports operator overloading even though it doesn’t have operators. Operators are methods with a crafty method naming convention. You saw that the first character of a method decides the precedence. Here we see that the last character of their names also has an effect—it determines the target of the method call.

The convention of : may be surprising at first, but as you get used to it (or as you “develop ...

Get Pragmatic Scala now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.