Authors:
Alexandre Bergel
1
and
Lorenzo Bettini
2
Affiliations:
1
University of Chile, Chile
;
2
Università di Torino, Italy
Keyword(s):
Generic programming, Java generics, C++ templates.
Related
Ontology
Subjects/Areas/Topics:
Programming Languages
;
Software Engineering
Abstract:
By abstracting over types, generic programming enables one to write code that is independent from specific data type implementation. This style is supported by most mainstream languages, including C++ with templates and Java with generics. If some code is not designed in a generic way from the start, a major effort is required to convert this code to use generic types. This conversion is manually realized which is known to be tedious and error-prone.
We propose Reverse Generics, a general linguistic mechanism to define a generic class from a non-generic class. For a given set of types, a generic is formed by unbinding static dependencies contained in these types. This generalization and generic type instantiation may be done incrementally. This paper studies the possible application of this linguistic mechanism to C++ and Java and, in particular, it reviews limitations of Java generics against our proposal.