Skip to main content
QUICK REVIEW

[Paper Review] Java & Lambda: a Featherweight Story

Lorenzo Bettini, Viviana Bono|arXiv (Cornell University)|Jan 15, 2018
Logic, programming, and type systemsComputer Science2 references4 citations
TL;DR

This paper introduces FJλ, a formal core calculus extending Featherweight Java with interfaces, multiple inheritance, lambda expressions, and intersection types. It establishes type safety via subject reduction and progress, demonstrating how Java 8's lambda and intersection type features are formally grounded in a minimal, type-safe model.

ABSTRACT

We present FJ&$\lambda$, a new core calculus that extends Featherweight Java (FJ) with interfaces, supporting multiple inheritance in a restricted form, $\lambda$-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 $\lambda$-expression and in the typing of conditional expressions. We also embody interface \emph{default methods} in FJ&$\lambda$, since they increase the dynamism of $\lambda$-expressions, by allowing these methods to be called on $\lambda$-expressions. The crucial point in Java 8 and in our calculus is that $\lambda$-expressions can have various types according to the context requirements (target types): indeed, Java code does not compile when $\lambda$-expressions come without target types. In particular, in the operational semantics we must record target types by decorating $\lambda$-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&$\lambda$ has been driven by the aim of making it a subset of Java 8, while preserving the elegance and compactness of FJ. Indeed, FJ&$\lambda$ programs are typed and behave the same as Java programs.

Motivation & Objective

  • To formally model Java 8's integration of lambda expressions and intersection types within a minimal core calculus.
  • To address the challenge of context-dependent typing in lambdas, where target types are essential for type inference and runtime behavior.
  • To preserve the elegance and type safety of Featherweight Java while extending it with modern Java 8 features.
  • To prove that the resulting calculus, FJλ, maintains subject reduction and progress, ensuring type safety.
  • To explore the role of intersection types in type casting, conditional expressions, and method invocation on lambda expressions.

Proposed method

  • Extends Featherweight Java (FJ) with interfaces supporting restricted multiple inheritance and default methods.
  • Introduces lambda expressions with target types, decorated at runtime to preserve context-dependent types.
  • Employs intersection types (using & notation) to represent multiple interface types, with structural subtyping rules only on intersections.
  • Defines a bidirectional type system combining standard type checking and type inference for lambdas, using target types as context constraints.
  • Incorporates a type inference algorithm that deduces the type of a program from a class table and term.
  • Proves subject reduction and progress for the calculus, ensuring type safety under operational semantics.

Experimental results

Research questions

  • RQ1How can lambda expressions in Java 8 be formally modeled in a core calculus with context-dependent typing?
  • RQ2What is the role of intersection types in enabling multiple functional interface types for lambdas and in conditional expressions?
  • RQ3How can target types be preserved during operational semantics to ensure type safety?
  • RQ4How do default methods in interfaces enhance the dynamism of lambda expressions in the calculus?
  • RQ5What formal guarantees (e.g., subject reduction, progress) can be proven for a calculus combining object-oriented and functional features?

Key findings

  • FJλ successfully extends Featherweight Java with lambda expressions and intersection types while preserving subject reduction and progress.
  • The calculus proves that Java 8's lambda and intersection type features are type-safe, as formalized by the subject reduction and progress theorems.
  • Intersection types are essential for typing conditional expressions and for casting lambda expressions to multiple functional interface types.
  • The use of target types in lambda expressions is formally justified, as their absence leads to type errors, and they must be preserved at runtime via decoration.
  • The calculus introduces a novel subtyping rule [<: &L] for intersection types, which, to the authors' knowledge, had not been previously formalized in this context.
  • The formalization demonstrates that generic types and functional interface intersections pose significant challenges, suggesting future work on extending FJ&lambda; to support generics.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.