REVERSE GENERICS - Parametrization after the Fact

Alexandre Bergel, Lorenzo Bettini



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.


  1. Allen, E., Bannet, J., and Cartwright, R. (2003). A FirstClass Approach to Genericity. In Proc. of OOPSLA, pages 96-114. ACM.
  2. Allen, E. E. and Cartwright, R. (2006). Safe instantiation in generic java. Sci. Comput. Program., 59(1-2):26-37.
  3. Austern, M. H. (1998). Generic Programming and the STL: using and extending the C++ Standard Template Library. Addison-Wesley.
  4. Batov, V. (2004). Java generics and C++ templates. C/C++ Users Journal, 22(7):16-21.
  5. Bracha, G., Odersky, M., Stoutamire, D., and Wadler, P. (1998). Making the future safe for the past: adding genericity to the Java programming language. In Proc. of OOPSLA, pages 183-200. ACM.
  6. Dos Reis, G. and Järvi, J. (2005). What is generic programming? In Proc. of LCSD.
  7. Duggan, D. (1999). Modular type-based reverse engineering of parameterized types in java code. In Proc. of OOPSLA, pages 97-113. ACM.
  8. Gamma, E., Helm, R., Johnson, R., and Vlissides, J. (1995). Design Patterns: Elements of Reusable Object-Oriented Software. Addison Wesley.
  9. Ghosh, D. (2004). Generics in Java and C++: a comparative model. ACM SIGPLAN Notices, 39(5):40-47.
  10. Igarashi, A. and Nagira, H. (2007). Union Types for Object Oriented Programming. Journal of Object Technology, 6(2):31-52.
  11. Igarashi, A., Pierce, B., and Wadler, P. (2001). Featherweight Java: A minimal core calculus for Java and GJ. ACM TOPLAS, 23(3):396-450.
  12. Kiezun, A., Ernst, M. D., Tip, F., and Fuhrer, R. M. (2007). Refactoring for parameterizing java classes. In Proc. of ICSE, pages 437-446. IEEE.
  13. Meyer, B. (1992). Eiffel: The Language. Prentice-Hall.
  14. Moors, A., Piessens, F., and Odersky, M. (2008). Generics of a higher kind. In Proc. of OOPSLA, pages 423-438. ACM.
  15. Musser, D. R. and Saini, A. (1996). STL Tutorial and Reference Guide. Addison Wesley.
  16. Musser, D. R. and Stepanov, A. A. (1989). Generic programming. In Gianni, P. P., editor, Proc. of ISSAC, volume 358 of LNCS, pages 13-25. Springer.
  17. Odersky, M., Spoon, L., and Venners, B. (2008). Programming in Scala. Artima.
  18. Odersky, M. and Wadler, P. (1997). Pizza into Java: Translating theory into practice. In Proc. of POPL, pages 146-159. ACM.
  19. Siek, J. and Taha, W. (2006). A semantic analysis of C++ templates. In Proc. of ECOOP, volume 4067 of LNCS, pages 304-327. Springer.
  20. von Dincklage, D. and Diwan, A. (2004). Converting Java classes to use generics. In Proc. pf OOPSLA, pages 1-14. ACM.

Paper Citation

in Harvard Style

Bergel A. and Bettini L. (2009). REVERSE GENERICS - Parametrization after the Fact . In Proceedings of the 4th International Conference on Software and Data Technologies - Volume 1: ICSOFT, ISBN 978-989-674-009-2, pages 39-46. DOI: 10.5220/0002252700390046

in Bibtex Style

author={Alexandre Bergel and Lorenzo Bettini},
title={REVERSE GENERICS - Parametrization after the Fact},
booktitle={Proceedings of the 4th International Conference on Software and Data Technologies - Volume 1: ICSOFT,},

in EndNote Style

JO - Proceedings of the 4th International Conference on Software and Data Technologies - Volume 1: ICSOFT,
TI - REVERSE GENERICS - Parametrization after the Fact
SN - 978-989-674-009-2
AU - Bergel A.
AU - Bettini L.
PY - 2009
SP - 39
EP - 46
DO - 10.5220/0002252700390046