On Flexible Dynamic Trait Replacement for Java-like Languages
Lorenzo Bettini, Sara Capecchi, Ferruccio Damiani

Dynamic trait replacement is a programming language feature for changing the objects' behavior at runtime by replacing some of the objects' methods. In previous work on dynamic trait replacement for Java-like languages, the object's methods that may be replaced must correspond exactly to a named trait used in the object's class definition. In this paper we propose the notion of replaceable: a programming language feature that decouples trait replacement operation code and class declaration code, thus making it possible to refactor classes and/or performing unanticipated trait replacement operations without invalidating existing code. We give a formal account of our proposal through a core calculus, FDJ (Featherweight Dynamic Java), equipped with a static type system guaranteeing that in a well-typed program no runtime type error will take place.