Choosing Efficient Inheritance Patterns for Java Generics

Elena Machkasova
Isaac Sjoblom
Fernando Trinciante

Presented at Midwest Instruction and Computing Symposium 2010 and received Best Undergraduate Student Paper Award.

Abstract

Java generic types allow a programmer to create parameterized data structures and methods. For instance, a generic Stack type may be used for integers in one instance and for strings in another. Java compiler guarantees in this case that integers and strings are not mixed in the same stack. We study runtime efficiency of a certain inheritance pattern related to Java generic types: narrowing of a type bound. This pattern takes place when a generic type allows a more restricted type of elements than its supertype. We examine a slowdown caused by this pattern for some method calls and study the reasons for it. Knowing cases when the slowdown takes place and the reasons for it would allow software developers to make informed choices when using generic types in their programs.