Java Wildcards Meet Definition-Site Variance

  • John Altidor
  • Christoph Reichenbach
  • Yannis Smaragdakis
Part of the Lecture Notes in Computer Science book series (LNCS, volume 7313)

Abstract

Variance is concerned with the interplay of parametric polymorphism (i.e., templates, generics) and subtyping. The study of variance gives answers to the question of when an instantiation of a generic class can be a subtype of another. In this work, we combine the mechanisms of use-site variance (as in Java) and definition-site variance (as in Scala and C#) in a single type system, based on Java. This allows maximum flexibility in both the specification and use of generic types, thus increasing the reusability of code. Our VarJ calculus achieves a safe synergy of def-site and use-site variance, while supporting the full complexities of the Java realization of variance, including F-bounded polymorphism and wildcard capture. We show that the interaction of these features with definition-site variance is non-trivial and offer a full proof of soundness—the first in the literature for an approach combining variance mechanisms.

Keywords

Type System Type Variable Variance Annotation Type Check Method Invocation 
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.

Preview

Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.

References

  1. 1.
    Altidor, J., Huang, S.S., Smaragdakis, Y.: Taming the wildcards: Combining definition- and use-site variance. In: Programming Language Design and Implementation, PLDI (2011)Google Scholar
  2. 2.
    America, P., van der Linden, F.: A parallel object-oriented language with inheritance and subtyping. In: European Conf. on Object-Oriented Programming and Object-Oriented Programming Systems, Languages, and Applications, OOPSLA/ECOOP (1990)Google Scholar
  3. 3.
    Bracha, G., Griswold, D.: Strongtalk: typechecking smalltalk in a production environment. In: Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (1993)Google Scholar
  4. 4.
    Cameron, N., Drossopoulou, S., Ernst, E.: A Model for Java with Wildcards. In: Ryan, M. (ed.) ECOOP 2008. LNCS, vol. 5142, pp. 2–26. Springer, Heidelberg (2008)CrossRefGoogle Scholar
  5. 5.
    Chin, W.-N., Craciun, F., Khoo, S.-C., Popeea, C.: A flow-based approach for variant parametric types. In: Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2006)Google Scholar
  6. 6.
    Cimadamore, M., Viroli, M.: Reifying wildcards in Java using the EGO approach. In: SAC 2007: Proceedings of the 2007 ACM Symposium on Applied Computing (2007)Google Scholar
  7. 7.
    Cook, W.: A proposal for making Eiffel type-safe. In: European Conf. on Object-Oriented Programming, ECOOP (1989)Google Scholar
  8. 8.
    Emir, B., Kennedy, A., Russo, C.V., Yu, D.: Variance and Generalized Constraints for C# Generics. In: Hu, Q. (ed.) ECOOP 2006. LNCS, vol. 4067, pp. 279–303. Springer, Heidelberg (2006)CrossRefGoogle Scholar
  9. 9.
    Hejlsberg, A., Wiltamuth, S., Golde, P.: C# Language Specification. Addison-Wesley Longman Publishing Co., Inc., Boston (2003)Google Scholar
  10. 10.
    Igarashi, A., Viroli, M.: On Variance-Based Subtyping for Parametric Types. In: Deng, T. (ed.) ECOOP 2002. LNCS, vol. 2374, pp. 441–469. Springer, Heidelberg (2002)CrossRefGoogle Scholar
  11. 11.
    Igarashi, A., Viroli, M.: Variant parametric types: A flexible subtyping scheme for generics. ACM Trans. Program. Lang. Syst. 28(5), 795–847 (2006)CrossRefGoogle Scholar
  12. 12.
    Igarashi, A., Viroli, M.: Variant path types for scalable extensibility. In: Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2007)Google Scholar
  13. 13.
    Kennedy, A.J., Pierce, B.C.: On decidability of nominal subtyping with variance, 2006. In: FOOL-WOOD 2007 (2007)Google Scholar
  14. 14.
    Odersky, M.: The Scala Language Specification v 2.8 (2010)Google Scholar
  15. 15.
    Smith, D., Cartwright, R.: Java type inference is broken: can we fix it? In: Object-Oriented Programming Systems, Languages, and Applications, OOPSLA (2008)Google Scholar
  16. 16.
    Tate, R., Leung, A., Lerner, S.: Taming wildcards in Java’s type system. In: Programming Language Design and Implementation, PLDI (2011)Google Scholar
  17. 17.
    Thorup, K.K., Torgersen, M.: Unifying Genericity: Combining the Benefits of Virtual Types and Parameterized Classes. In: Guerraoui, R. (ed.) ECOOP 1999. LNCS, vol. 1628, pp. 186–204. Springer, Heidelberg (1999)CrossRefGoogle Scholar
  18. 18.
    Torgersen, M., Hansen, C.P., Ernst, E., von der Ahe, P., Bracha, G., Gafter, N.: Adding wildcards to the Java programming language. In: SAC 2004: Proc. of the 2004 Symposium on Applied Computing (2004)Google Scholar
  19. 19.
    Urban, C., Berghofer, S., Norrish, M.: Barendregt’s Variable Convention in Rule Inductions. In: Pfenning, F. (ed.) CADE 2007. LNCS (LNAI), vol. 4603, pp. 35–50. Springer, Heidelberg (2007)CrossRefGoogle Scholar
  20. 20.
    Viroli, M., Rimassa, G.: On access restriction with Java wildcards. Journal of Object Technology 4(10), 117–139 (2005)CrossRefGoogle Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • John Altidor
    • 1
  • Christoph Reichenbach
    • 1
  • Yannis Smaragdakis
    • 1
    • 2
  1. 1.University of MassachusettsAmherstUSA
  2. 2.University of AthensGreece

Personalised recommendations