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

Appendix A: Code Listings

For the full source, see https://github.com/tobyweston/learn-scala-java-devs . The following is a selection of examples from the text, expanded to provide fuller context for your reference.

Inheritance

Subtype Inheritance in Java

package s4j.java.chapter12 ;
public class Customer implements Comparable<Customer> {
     private final String name;
     private final String address;
     private final ShoppingBasket basket = new ShoppingBasket();
     public Customer(String name, String address) {
         this .name = name;
         this .address = address;
    }
     public void add(Item item) {
        basket.add(item);
    }
     public Double total() {
         return basket.value();
    }
}
package s4j.java.chapter12 ...

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