Research output: Contribution to book/anthology/report/proceeding › Article in proceedings › Research › peer-review
Guarded Type Promotion : Eliminating Redundant Casts in Java. / Winther, Johnni.
Proceedings of the 13th Workshop on Formal Techniues for Java-Like Programs . Association for Computing Machinery, 2011.Research output: Contribution to book/anthology/report/proceeding › Article in proceedings › Research › peer-review
}
TY - GEN
T1 - Guarded Type Promotion
T2 - Formal Techniques for Java-Like Programs
AU - Winther, Johnni
N1 - Conference code: 13
PY - 2011
Y1 - 2011
N2 - 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.
AB - 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.
KW - Java
KW - type cast
KW - type checking
U2 - 10.1145/2076674.2076680
DO - 10.1145/2076674.2076680
M3 - Article in proceedings
SN - 978-1-4503-0893-9
BT - Proceedings of the 13th Workshop on Formal Techniues for Java-Like Programs
PB - Association for Computing Machinery
Y2 - 26 July 2011 through 26 July 2011
ER -