Reverse Generics: Parametrization after the Fact

  • Alexandre Bergel
  • Lorenzo Bettini
Conference paper
Part of the Communications in Computer and Information Science book series (CCIS, volume 50)


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.


Generic Programming Type Constructor Reverse Generic Public Class Standard Template Library 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


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

Copyright information

© Springer-Verlag Berlin Heidelberg 2011

Authors and Affiliations

  • Alexandre Bergel
    • 1
  • Lorenzo Bettini
    • 2
  1. 1.PLEIAD Laboratory, Computer Science Department (DCC)University of ChileSantiagoChile
  2. 2.Dipartimento di InformaticaUniversità di TorinoItaly

Personalised recommendations