Home » JVM Languages » Scala » Scala Wonderland: All operations are method calls

About Rado Buransky

Rado Buransky

Scala Wonderland: All operations are method calls

I’ve started learning Scala two months ago and I can’t get back to Murakami’s 1Q84 so exciting it is. In the coming series I’d like to share my excitement with you. It won’t be yet another step-by-step tutorial. I’ll share features that made me think (IBM should be proud of me). For whatever reason.

val i = 1 + 2

… is equal to …

val i = (1).+(2)

Scala doesn’t have operators. It has methods with names like +, -, *, / instead. The code above invokes method named “+” on the object Int representing number 1 passing Int object of value 2 as an argument.

Note that you don’t have to type “.” to ivoke a method on an object and also you don’t need to provide parentheses around method arguments. This knowledge helps a lot when trying to understand what is a program written in Scala actually doing.

Stay tuned!

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
Email address:

Leave a Reply

Be the First to Comment!

Notify of