top

UML diagrams of Java conversions

These UML diagrams were my slides for a presentation on Java type conversions that I gave as a guest participant in an AG Communications study group.

These diagrams describe the compile-time checks that the compiler performs on conversions. I have abused UML in this way: Whenever you see a dotted line with an arrow, it means you can convert from the source type to the destination type (in standard UML, a dotted line means "depends on.")

Primitive type conversions are easy, so I discussed reference conversions. There are two types of conversions: widening conversions and narrowing conversions.

Widening conversions are the ones you get for free--you can use a cast if you want, but you don't have to. The compiler will automatically perform widening conversions for you. There is never a runtime check for widening conversions--the compiler has enough information at compile-time to check the validity of a widening conversion.

Narrowing conversions require a cast, and involve both a compile-time check and a runtime check. The compiler first checks at compile time to see if the conversion is possible or not. Then at runtime the VM checks to see if the source type is actually an instance of the destination type.

References:


Copyright (c) 1998 by Wayne E. Conrad, All Rights Reserved
Last Updated May 6, 1998
This page has been accidentally visited times since May 1st, 1998.
HTML DTD Validated Best Viewed With Any Browser

This page hosted by Get your own Free Home Page