Abstract
Java 5, the most recent major update to the Java Programming Language, introduced a number of sophisticated features, including a major extension to the type system. While the technical details of these new features are complex, much of this complexity is hidden from the typical Java developer by an ambitious type inference mechanism. Unfortunately, the extensions to the Java 5 type system were so novel that their technical details had not yet been thoroughly investigated in the research literature. As a result, the Java 5 compiler includes a pragmatic but flawed type inference algorithm that is, by design, neither sound nor locally complete. The language specification points out that neither of these failures is catastrophic: the correctness of potentially-unsound results must be verified during type checking; and incompleteness can usually be worked around by manually providing the method type parameter bindings for a given call site.
This paper dissects the type inference algorithm of Java 5 and proposes a signficant revision that is sound and able to calculate correct results where the Java 5 algorithm fails. The new algorithm is locally complete with the exception of a difficult corner case. Moreover, the new algorithm demonstrates that several arbitrary restrictions in the Java type system---most notably the ban on lower-bounded type parameter declarations and the limited expressibility of intersection types---are unnecessary. We hope that this work will spur the evolution of a more coherent, more comprehensive generic type system for Java.
- Gilad Bracha, Martin Odersky, David Stoutamire, & Philip Wadler. Making the Future Safe for the Past: Adding Genericity to the Java Programming Language. OOPSLA, 1998. Google Scholar
Digital Library
- Luca Cardelli. An Implementation of F:. Research report 97, DEC Systems Research Center, 1993.Google Scholar
- James Gosling, Bill Joy, Guy Steele, & Gilad Bracha. The Java Language Specification, Third Edition. 2005. Google Scholar
Digital Library
- Atshushi Igarashi, Benjamin Pierce, & Philip Wadler. Featherweight Java: A Minimal Core Calculus for Java and GJ. OOPSLA, 1999. Google Scholar
Digital Library
- Atsushi Igarashi & Mirko Viroli. On Variance-Based Subtyping for Parameteric Types. ECOOP, 2002. Google Scholar
Digital Library
- Atsushi Igarashi & Hideshi Nagira. Union Types for Object-Oriented Programming. Journal of Object Technology, vol. 6, no. 2, February 2007.Google Scholar
- Andrew J. Kennedy & Benjamin C. Pierce. On Decidability of Nominal Subtyping with Variance. FOOL/WOOD, 2007.Google Scholar
- Benjamin C. Pierce & David N. Turner. Local Type Argument Synthesis with Bounded Quantification. Technical report TR495, Indiana University, 1997.Google Scholar
- Benjamin C. Pierce & David N. Turner. Local Type Inference. POPL, 1998. Google Scholar
Digital Library
- Daniel Smith. Completing the Java Type System. Master's thesis, Rice University, 2007.Google Scholar
- Kresten Krab Thorup & Mads Torgersen. Unifying Genericity: Combining the Benefits of Virtual Types and Parameterized Classes. Lecture Notes in Computer Science, 1999.Google Scholar
- Mads Torgersen, Christian Plesner Hansen, Erik Ernst, Peter von der Ahé, Gilad Bracha, & Neal Gafter. Adding Wildcards to the Java Programming Language. SAC, 2004. Google Scholar
Digital Library
- Mads Torgersen, Erik Ernst, & Christian Plesner Hansen. Wild FJ. FOOL, 2005.Google Scholar
- DrJava IDE. http://drjava.org.Google Scholar
- Java Community Process. http://jcp.org.Google Scholar
- "Type variables should have lower/super bounds." Java Request for Enhancement. http://bugs.sun.com/view_bug.do?bug_id=5052956.Google Scholar
- "Please introduce a name for the "null' type." Java Request for Enhancement. http://bugs.sun.com/view_bug.do?bug_id=5060259.Google Scholar
- "Multiply-bounded reference type expressions." Java Request for Enhancement. http://bugs.sun.com/view_bug.do?bug_id=6350706.Google Scholar
Index Terms
Java type inference is broken: can we fix it?
Recommendations
Java type inference is broken: can we fix it?
OOPSLA '08: Proceedings of the 23rd ACM SIGPLAN conference on Object-oriented programming systems languages and applicationsJava 5, the most recent major update to the Java Programming Language, introduced a number of sophisticated features, including a major extension to the type system. While the technical details of these new features are complex, much of this complexity ...
Taming wildcards in Java's type system
PLDI '11Wildcards 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 ...
Taming wildcards in Java's type system
PLDI '11: Proceedings of the 32nd ACM SIGPLAN Conference on Programming Language Design and ImplementationWildcards 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 ...







Comments