We present FJ&, a new core calculus that extends Featherweight Java (FJ) with interfaces, supporting multiple inheritance in a restricted form, -expressions, and intersection types. Our main goal is to formalise how lambdas and intersection types are grafted on Java 8, by studying their properties in a formal setting. We show how intersection types play a significant role in several cases, in particular in the typecast of a -expression and in the typing of conditional expressions. We also embody interface \emph{default methods} in FJ&, since they increase the dynamism of -expressions, by allowing these methods to be called on -expressions. The crucial point in Java 8 and in our calculus is that -expressions can have various types according to the context requirements (target types): indeed, Java code does not compile when -expressions come without target types. In particular, in the operational semantics we must record target types by decorating -expressions, otherwise they would be lost in the runtime expressions. We prove the subject reduction property and progress for the resulting calculus, and we give a type inference algorithm that returns the type of a given program if it is well typed. The design of FJ& has been driven by the aim of making it a subset of Java 8, while preserving the elegance and compactness of FJ. Indeed, FJ& programs are typed and behave the same as Java programs.

Java & Lambda: a Featherweight Story

Lorenzo Bettini;Viviana Bono;Mariangiola Dezani-Ciancaglini;Paola Giannini;
2018-01-01

Abstract

We present FJ&, a new core calculus that extends Featherweight Java (FJ) with interfaces, supporting multiple inheritance in a restricted form, -expressions, and intersection types. Our main goal is to formalise how lambdas and intersection types are grafted on Java 8, by studying their properties in a formal setting. We show how intersection types play a significant role in several cases, in particular in the typecast of a -expression and in the typing of conditional expressions. We also embody interface \emph{default methods} in FJ&, since they increase the dynamism of -expressions, by allowing these methods to be called on -expressions. The crucial point in Java 8 and in our calculus is that -expressions can have various types according to the context requirements (target types): indeed, Java code does not compile when -expressions come without target types. In particular, in the operational semantics we must record target types by decorating -expressions, otherwise they would be lost in the runtime expressions. We prove the subject reduction property and progress for the resulting calculus, and we give a type inference algorithm that returns the type of a given program if it is well typed. The design of FJ& has been driven by the aim of making it a subset of Java 8, while preserving the elegance and compactness of FJ. Indeed, FJ& programs are typed and behave the same as Java programs.
2018
14
3:17
1
24
https://lmcs.episciences.org/4803
Computer Science - Logic in Computer Science ; Computer Science - Programming Languages ;
Lorenzo Bettini, Viviana Bono, Mariangiola Dezani-Ciancaglini, Paola Giannini, Betti Venneri
File in questo prodotto:
File Dimensione Formato  
1801.05052.pdf

Accesso aperto

Tipo di file: PDF EDITORIALE
Dimensione 563.85 kB
Formato Adobe PDF
563.85 kB Adobe PDF Visualizza/Apri

I documenti in IRIS sono protetti da copyright e tutti i diritti sono riservati, salvo diversa indicazione.

Utilizza questo identificativo per citare o creare un link a questo documento: https://hdl.handle.net/2318/1686823
Citazioni
  • ???jsp.display-item.citation.pmc??? ND
  • Scopus 30
  • ???jsp.display-item.citation.isi??? 3
social impact