skip to main content
research-article

Taming wildcards in Java's type system

Published:04 June 2011Publication History
Skip Abstract Section

Abstract

Wildcards have become an important part of Java's type system since their introduction 7 years ago. Yet there are still many open problems with Java's wildcards. For example, there are no known sound and complete algorithms for subtyping (and consequently type checking) Java wildcards, and in fact subtyping is suspected to be undecidable because wildcards are a form of bounded existential types. Furthermore, some Java types with wildcards have no joins, making inference of type arguments for generic methods particularly difficult. Although there has been progress on these fronts, we have identified significant shortcomings of the current state of the art, along with new problems that have not been addressed.

In this paper, we illustrate how these shortcomings reflect the subtle complexity of the problem domain, and then present major improvements to the current algorithms for wildcards by making slight restrictions on the usage of wildcards. Our survey of existing Java programs suggests that realistic code should already satisfy our restrictions without any modifications. We present a simple algorithm for subtyping which is both sound and complete with our restrictions, an algorithm for lazily joining types with wildcards which addresses some of the shortcomings of prior work, and techniques for improving the Java type system as a whole. Lastly, we describe various extensions to wildcards that would be compatible with our algorithms.

References

  1. Gilad Bracha, Martin Odersky, David Stoutamire, and Philip Wadler. Making the future safe for the past: Adding genericity to the Java programming language. In OOPSLA, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Nicholas Cameron and Sophia Drossopoulou. On subtyping, wildcards, and existential types. In FTfJP, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. Nicholas Cameron, Sophia Drossopoulou, and Erik Ernst. A model for Java with wildcards. In ECOOP, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. Peter Canning, William Cook, Walter Hill, Walter Olthoff, and John C. Mitchell. \hboxF-bounded polymorphism for object-oriented programming. In FPCA, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. James Gosling, Bill Joy, Guy Steel, and Gilad Bracha. The Java#8482; Language Specification. Addison-Wesley Professional, third edition, June 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Atsushi Igarashi and Mirko Viroli. On variance-based subtyping for parametric types. In ECOOP, 2002. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Simon Peyton Jones, Dimitrios Vytiniotis, Stephanie Weirich, and Mark Shields. Practical type inference for arbitrary-rank types. Journal of Functional Programming, 17:1--82, January 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. Andrew Kennedy and Benjamin Pierce. On decidability of nominal subtyping with variance. In FOOL, 2007.Google ScholarGoogle Scholar
  9. Daan Leijen. HMF: Simple type inference for first-class polymorphism. In ICFP, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Martin Odersky and Konstantin Läufer. Putting type annotations to work. In POPL, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. Gordon D. Plotkin. A note on inductive generalization. In Machine Intelligence, volume 5, pages 153--163. Edinburgh University Press, 1969.Google ScholarGoogle Scholar
  12. John C. Reynolds. Transformational systems and the algebraic structure of atomic formulas. In Machine Intelligence, volume 5, pages 135--151. Edinburgh University Press, 1969.Google ScholarGoogle Scholar
  13. Daniel Smith and Robert Cartwright. Java type inference is broken: Can we fix it? In OOPSLA, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Alexander J. Summers, Nicholas Cameron, Mariangiola Dezani-Ciancaglini, and Sophia Drossopoulou. Towards a semantic model for Java wildcards. In FTfJP, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Ross Tate, Alan Leung, and Sorin Lerner. Taming wildcards in Java's type system. Technical report, University of California, San Diego, March 2011.Google ScholarGoogle Scholar
  16. Kresten Krab Thorup and Mads Torgersen. Unifying genericity - combining the benefits of virtual types and parameterized classes. In ECOOP, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Mads Torgersen, Erik Ernst, and Christian Plesner Hansen. Wild FJ. In FOOL, 2005.Google ScholarGoogle Scholar
  18. Mads Torgersen, Christian Plesner Hansen, Erik Ernst, Peter von der Ahé, Gilad Bracha, and Neal Gafter. Adding wildcards to the Java programming language. In SAC, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Mirko Viroli. On the recursive generation of parametric types. Technical Report DEIS-LIA-00-002, Università di Bologna, September 2000.Google ScholarGoogle Scholar
  20. Stefan Wehr and Peter Thiemann. On the decidability of subtyping with bounded existential types. In APLAS, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Taming wildcards in Java's type system

        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

        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!