Adding wildcards to the Java programming language
Proceedings of the 2004 ACM symposium on Applied computing
Java(TM) Language Specification, The (3rd Edition) (Java (Addison-Wesley))
Java(TM) Language Specification, The (3rd Edition) (Java (Addison-Wesley))
The design and implementation of typed scheme
Proceedings of the 35th annual ACM SIGPLAN-SIGACT symposium on Principles of programming languages
Logical types for untyped languages
Proceedings of the 15th ACM SIGPLAN international conference on Functional programming
Typing local control and state using flow analysis
ESOP'11/ETAPS'11 Proceedings of the 20th European conference on Programming languages and systems: part of the joint European conferences on theory and practice of software
Static single information form for abstract compilation
TCS'12 Proceedings of the 7th IFIP TC 1/WG 202 international conference on Theoretical Computer Science
Improving precision of generated ASTs
Proceedings of the Twelfth Workshop on Language Descriptions, Tools, and Applications
Hi-index | 0.00 |
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.