Refactoring Techniques for Migrating Applications to Generic Java Container Classes

Version 1.5 of the Java programming language will include generics, a language construct for associating type parameters with classes and methods. Generics are particularly useful for creating statically type-safe, reusable container classes such that a store of an inappropriate type causes a compile-time error, and that no down-casting is needed when retrieving elements. The standard libraries released with Java 1.5 will include generic versions of popular container classes such as HashMap and ArrayList. This paper presents a method for refactoring Java programs that use current container classes into equivalent Java 1.5 programs that use their new generic counterparts. Our method uses a variation on an existing model of type constraints to infer the element types of container objects, and it is parameterized by how much, if any, context sensitivity to exploit when generating these type constraints. We present both a context-insensitive instantiation of the framework and one using a low-cost variation on Agesen’s Cartesian Product Algorithm. The method has been implemented in Eclipse, a popular open-source development environment for Java. We evaluated our approach on several small benchmark programs, and found that, in all but one case, between 40% and 100% of all casts can be removed.

By: Frank Tip, Robert Fuhrer, Julian Dolby, Adam Kiezun

Published in: RC23238 in 2004

LIMITED DISTRIBUTION NOTICE:

This Research Report is available. This report has been submitted for publication outside of IBM and will probably be copyrighted if accepted for publication. It has been issued as a Research Report for early dissemination of its contents. In view of the transfer of copyright to the outside publisher, its distribution outside of IBM prior to publication should be limited to peer communications and specific requests. After outside publication, requests should be filled only by reprints or legally obtained copies of the article (e.g., payment of royalties). I have read and understand this notice and am a member of the scientific community outside or inside of IBM seeking a single copy only.

rc23238.pdf

Questions about this service can be mailed to reports@us.ibm.com .