O'Reilly logo

Scala for Java Developers: A Practical Primer by Toby Weston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required