© Toby Weston 2018
Toby WestonScala for Java Developershttps://doi.org/10.1007/978-1-4842-3108-1_10

10. Classes and Functions

Toby Weston
(1)
London, UK
 
In this chapter we’ll look at the following:
  • Anonymous functions or lambdas.
  • How anonymous classes differ from anonymous functions.
  • First-class and higher-order functions.
  • The differences between a function and a method.
  • The differences between lambdas and closures.

Anonymous Functions

A function in the general sense is a code fragment designed to perform a specific task or calculation. You can create a function as a Java method or a Scala def. Both by their nature are named. Anonymous functions, on the other hand, do not have a name.
An anonymous function is also called a lambda and when used can ...

Get Scala for Java Developers: A Practical Primer 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.