ComputingComputer ScienceCompilersFormal MethodsProgramming LanguagesCompiler ConstructionControl-flow AnalysisType CheckingType SystemsDefensive ProgrammingDynamic Type CheckingRuntime SafetyRuntime Type CheckingRuntime Type SystemsStatic Type CheckingType SafetyType-level Programming
In Java, explicit casts are ubiquitous since they bridge the gap between compile-time and runtime type safety. Since casts potentially throw a ClassCastException, many programmers use a defensive programming style of guarded casts. In this programming style casts are protected by a preceding conditional using the instanceof operator and thus the cast type is redundantly mentioned twice. We propose a new typing rule for Java called Guarded Type Promotion aimed at eliminating the need for the explicit casts when guarded. This new typing rule is backward compatible and has been fully implemented in a Java 6 compiler. Through our extensive testing of real-life code we show that guarded casts account for approximately one fourth of all casts and that Guarded Type Promotion can eliminate the need for 95 percent of these guarded casts.
4
The design and implementation of typed scheme
Sam Tobin-Hochstadt, Matthias Felleisen · 2008 · 313 citations
Logical types for untyped languages
Sam Tobin-Hochstadt, Matthias Felleisen · 2010 · 131 citations
Adding wildcards to the Java programming language
Mads Torgersen, Christian Plesner Hansen, Erik Ernst et al. · 2004 · 107 citations
Adding Wildcards to the Java Programming Language.
Mads Torgersen, Erik Ernst, Christian Plesner Hansen et al. · The Journal of Object Technology · 2004 · 52 citations · Full text