JavaTraits Preprocessor

This project was created as part of a masters thesis by Kjetil Østerås. The thesis was finished in May 2007 and has the title "Traits in Java". The goal of the thesis was to create a preprocessor for Java that implemented the traits feature. Feel free to download the code and test it out yourself. It was supervised by professor Birger Møller-Pedersen from the department of informatics at the University of Oslo. Any comments or questions you may have on the thesis or on the provided traits preprocessor can be sent to kjetilos (at)

This is the abstract of the master thesis:

"A trait is a programming language feature which contains a collection of methods that can be reused across class hierarchies. Traits is a relatively new language feature that is beginning to be a part of some of the newest object-oriented programming languages. Traits have been implemented in some languages but it has not become a part of the Java language yet. In this thesis we apply traits to the Java 5 language by designing and implementing a traits aware preprocessor. The preprocessor translates a Java language extended with trait syntax into ordinary Java 5. The preprocessor builds abstract syntax trees of the input files and inserts traits by manipulating the abstract syntax trees. The preprocessor also contains a type-checker which ensures that the trait can be applied to a certain class.

This thesis describes the implementation of the traits preprocessor for Java and compares it to some other implementations of traits in statically typed languages."