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

8. Classes and Fields

Toby Weston
(1)
London, UK
 
In this chapter, we’ll have a look at the following:
  1. 1.
    Creating classes.
     
  2. 2.
    How Scala makes things easier when defining fields.
     
  3. 3.
    What happens behind the scenes when Scala creates methods for you.
     

Creating Classes

Creating a class in Java means writing something like this:
  // java
  public class Customer {
  }
It makes sense for us to have a name and address for a customer. So, adding these as fields and initializing via the constructor would give us something like this:
  // java
  public class Customer {
      private final String name;
      private final String address;
      public Customer(String ...

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.