skip to main content
research-article

Taming the wildcards: combining definition- and use-site variance

Published:04 June 2011Publication History
Skip Abstract Section

Abstract

Variance allows the safe integration of parametric and subtype polymorphism. Two flavors of variance, definition-site versus use-site variance, have been studied and have had their merits hotly debated. Definition-site variance (as in Scala and C#) offers simple type-instantiation rules, but causes fractured definitions of naturally invariant classes; Use-site variance (as in Java) offers simplicity in class definitions, yet complex type-instantiation rules that elude most programmers.

We present a unifying framework for reasoning about variance. Our framework is quite simple and entirely denotational, that is, it evokes directly the definition of variance with a small core calculus that does not depend on specific type systems. This general framework can have multiple applications to combine the best of both worlds: for instance, it can be used to add use-site variance annotations to the Scala type system. We show one such application in detail: we extend the Java type system with a mechanism that modularly infers the definition-site variance of type parameters, while allowing use-site variance annotations on any type-instantiation.

Applying our technique to six Java generic libraries (including the Java core library) shows that 20-58 (depending on the library) of generic definitions are inferred to have single-variance; 8-63% of method signatures can be relaxed through this inference, and up to 91% of existing wildcard annotations are unnecessary and can be elided.

References

  1. J. Altidor, S. S. Huang, and Y. Smaragdakis. Taming the wildcards: Combining definition- and use-site variance (extended version). http://www.cs.umass.edu/ yannis/variance-extended2011.pdf.Google ScholarGoogle Scholar
  2. P. America and F. van der Linden. A parallel object-oriented language with inheritance and subtyping. In OOPSLA/ECOOP '90: Proc. of the European Conf. on object-oriented programming on Object-oriented programming systems, languages, and applications, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Apache Software Foundation. Apache commons-collections library. http://larvalabs.com/collections/. Version 4.01.Google ScholarGoogle Scholar
  4. J. Bloch. The closures controversy. http://www.javac.info/bloch-closures-controversy.ppt. Accessed Nov. 2010.Google ScholarGoogle Scholar
  5. K. Boumillion and J. Levy. Guava: Google core libraries for Java 1.5Google ScholarGoogle Scholar
  6. . http://code.google.com/p/guava-libraries/. Accessed Nov. 2010.Google ScholarGoogle Scholar
  7. G. Bracha and D. Griswold. Strongtalk: typechecking smalltalk in a production environment. In OOPSLA '93: Proc. of the Conf. on Object-oriented programming systems, languages, and applications, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. N. Cameron, S. Drossopoulou, and E. Ernst. A model for Java with wildcards. In ECOOP '08: Proc. of the 22nd European Conf. on Object-Oriented Programming, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. R. Cartwright and J. Guy L. Steele. Compatible genericity with run-time types for the Java programming language. In OOPSLA '98: Proc. of the 13th ACM SIGPLAN Conf. on Object-oriented programming, systems, languages, and applications, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. W. Cook. A proposal for making eiffel type-safe. In ECOOP '89: Proc. of the 3rd European Conf. on Object-Oriented Programming, 1989.Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. J.-M. Dautelle et al. Jscience. http://jscience.org/. Accessed Nov. 2010.Google ScholarGoogle Scholar
  12. J.-M. Dautelle and W. Keil. Jsr-275: Measures and units. http://www.jcp.org/en/jsr/detail?id=275. Accessed Nov. 2010.Google ScholarGoogle Scholar
  13. M. Day, R. Gruber, B. Liskov, and A. C. Myers. Subtypes vs. where clauses: constraining parametric polymorphism. In OOPSLA '95: Proc. of the tenth annual Conf. on Object-oriented programming systems, languages, and applications, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. B. Emir, A. Kennedy, C. Russo, and D. Yu. Variance and generalized constraints for C\# generics. In ECOOP '06: Proc. of the European Conf. on Object-Oriented Programming, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. E. Friedman and R. Eden. Gnu Trove: High-performance collections library for Java. http://trove4j.sourceforge.net/. Version 2.1.0.Google ScholarGoogle Scholar
  16. A. Hejlsberg, S. Wiltamuth, and P. Golde. C\# Language Specification. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 2003. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. S. S. Huang, D. Zook, and Y. Smaragdakis. cJ: Enhancing Java with safe type conditions. In Proc. of the 6th Intl. Conf. on Aspect-Oriented Software Development, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. A. Igarashi and M. Viroli. Variant parametric types: A flexible subtyping scheme for generics. ACM Trans. Program. Lang. Syst., 28(5):795--847, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. A. Kennedy and D. Syme. Transposing f to c\#: expressivity of parametric polymorphism in an object-oriented language: Research articles. Concurr. Comput. : Pract. Exper., 16:707--733, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. A. Kiezun, M. Ernst, F. Tip, and R. Fuhrer. Refactoring for parameterizing Java classes. In ICSE '07: Proc. of the 29th Intl. Conf. on Software Engineering, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. M. Odersky. The Scala Language Specification v 2.8. 2010.Google ScholarGoogle Scholar
  22. A. Salcianu. Java program analysis utilities library. http://jpaul.sourceforge.net/. Version 2.5.1.Google ScholarGoogle Scholar
  23. K. K. Thorup and M. Torgersen. Unifying genericity: Combining the benefits of virtual types and parameterized classes. In ECOOP '99: Proc. of the European Conf. on Object-Oriented Programming, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. M. Torgersen, C. P. Hansen, E. Ernst, P. von der Ahe, G. Bracha, and N. Gafter. Adding wildcards to the Java programming language. In SAC '04: Proc. of the 2004 Symposium on Applied Computing, 2004.\endthebibliography Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Taming the wildcards: combining definition- and use-site variance

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 46, Issue 6
        PLDI '11
        June 2011
        652 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/1993316
        Issue’s Table of Contents
        • cover image ACM Conferences
          PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and Implementation
          June 2011
          668 pages
          ISBN:9781450306638
          DOI:10.1145/1993498
          • General Chair:
          • Mary Hall,
          • Program Chair:
          • David Padua

        Copyright © 2011 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 4 June 2011

        Check for updates

        Qualifiers

        • research-article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!