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.
- 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 Scholar
- 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 Scholar
Digital Library
- Apache Software Foundation. Apache commons-collections library. http://larvalabs.com/collections/. Version 4.01.Google Scholar
- J. Bloch. The closures controversy. http://www.javac.info/bloch-closures-controversy.ppt. Accessed Nov. 2010.Google Scholar
- K. Boumillion and J. Levy. Guava: Google core libraries for Java 1.5Google Scholar
- . http://code.google.com/p/guava-libraries/. Accessed Nov. 2010.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- W. Cook. A proposal for making eiffel type-safe. In ECOOP '89: Proc. of the 3rd European Conf. on Object-Oriented Programming, 1989.Google Scholar
Digital Library
- J.-M. Dautelle et al. Jscience. http://jscience.org/. Accessed Nov. 2010.Google Scholar
- J.-M. Dautelle and W. Keil. Jsr-275: Measures and units. http://www.jcp.org/en/jsr/detail?id=275. Accessed Nov. 2010.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- E. Friedman and R. Eden. Gnu Trove: High-performance collections library for Java. http://trove4j.sourceforge.net/. Version 2.1.0.Google Scholar
- A. Hejlsberg, S. Wiltamuth, and P. Golde. C\# Language Specification. Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 2003. Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- M. Odersky. The Scala Language Specification v 2.8. 2010.Google Scholar
- A. Salcianu. Java program analysis utilities library. http://jpaul.sourceforge.net/. Version 2.5.1.Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
Index Terms
Taming the wildcards: combining definition- and use-site variance
Recommendations
Taming the wildcards: combining definition- and use-site variance
PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and ImplementationVariance 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#) ...
Refactoring Java generics by inferring wildcards, in practice
OOPSLA '14: Proceedings of the 2014 ACM International Conference on Object Oriented Programming Systems Languages & ApplicationsWildcard annotations can improve the generality of Java generic libraries, but require heavy manual effort. We present an algorithm for refactoring and inferring more general type instantiations of Java generics using wildcards. Compared to past ...
Refactoring Java generics by inferring wildcards, in practice
OOPSLA '14Wildcard annotations can improve the generality of Java generic libraries, but require heavy manual effort. We present an algorithm for refactoring and inferring more general type instantiations of Java generics using wildcards. Compared to past ...







Comments