September 2015
Intermediate to advanced
250 pages
6h 40m
English
In Java, while methods can take multiple arguments, they can only return one result. Returning more than a single value needs clumsy workarounds in Java. For example, to return a person’s first name, last name, and email address we’d have to employ a Person class and return an array of Strings or an ArrayList. Scala’s Tuple, combined with multiple assignments, makes returning multiple values a simple task.
A tuple is an immutable object sequence created as comma-separated values. For example, the following represents a tuple with three objects: ("Venkat", "Subramaniam", "venkats@agiledeveloper.com").
You can assign the elements of a tuple into multiple vals or vars in parallel, as we see here:
| FromJavaToScala/MultipleAssignment.scala ... |
Read now
Unlock full access