© 2000 by British Computer Society
| ||||||||||||||||||||||||||||||||||||||||||||||||||||
Safe Structural Conformance for Java
1 Department of Mathematical and Computer Sciences, Loyola University Chicago, 6525 N. Sheridan Road, Chicago, IL 60626, USA Email: laufer@cs.luc.edu 2 Department of Computer and Information Science, The Ohio State University, 395 Dreese Lab., 2015 Neil Ave, Columbus, OH 43210-1277, USA 3 Lycos, Inc., 400-2 Totten Pond Road, Waltham, MA 02154, USA
In Java, an interface specifies public abstract methods and associated public constants. Conformance of a class to an interface is by name. We propose to allow structural conformance to interfaces: any class or interface that declares or implements each method in a target interface conforms structurally to the interface, and any expression of the source class or interface type can be used where a value of the target interface type is expected. We argue that structural conformance results in a major gain in flexibility in situations that require retroactive abstraction over types. Structural conformance requires no additional syntax and only small modifications to the Java compiler and optionally, for performance reasons, the virtual machine, resulting in a minor performance penalty. Our extension is type-safe: a cast-free program that compiles without errors will not have any type errors at run time. Our extension is conservative: existing Java programs still compile and run in the same manner as under the original language definition. Finally, structural conformance works well with recent extensions such as Java remote method invocation. We have implemented our extension of Java with structural interface conformance by modifying the Java Developers Kit 1.1.5 source release for Solaris and Windows 95/NT. We have also created a test suite for the extension.