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_13

13. Generics

Toby Weston
(1)
London, UK
 
In this chapter we’ll look at generics or type parameterization or generic programming in Scala. We’ll look at the following:
  • Syntax for generics: defining types and methods.
  • Bounded types, extends and super.
  • Wildcards in both Java and Scala.
  • Covariance and contravariance.

Parametric Polymorphism

We talked briefly about subtype or inclusion polymorphism ; the idea that subtypes can be substituted to stand in for their super-types. These stand-ins can provide different behavior without changing the structure of your code. The types of polymorphism are:
  • Inclusion polymorphism (see Chapter 11, Inheritance).
  • Ad hoc ...

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