Plt2013 7

(C) Ralf Lämmel, Andrei Varanovich, University of Koblenz Landau



Polymorphism, co/contra variance in java.

Demonstrate covariant subtyping of arrays in Java. Write a short Java program involving arrays that type-checks but fails (by raising an ArrayStoreException) at run time. Which properties of the language break the type safety?

Demonstrate a parametric polymorphism in Java, that it also illustrates co- and contra-variance.

Support your examples with running source code and typing rules.
Please consult "Types and Programming Languages" book, chapter 15, for the hints.

Casting support for records

Introduce the Top type (ala object) and Nat (natual numbers) for the records. Add a "casting" support, defining typing rules for downcast and upcast.

{key : Nat, value : Top} <: { key : Top, value : Top}