Abstract
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 safely 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.