integer local variable to an integer, value, and item-or-value
value or item-or-value, but containing an integer, to an integer
object or item-or-value, but containing a test-object, to another local variable typed as test-object
test-object, which inherits directly from object, to another local variable typed as test-object, object, or item-or-value
integer) to a general value type (value or item-or-value) are equally efficient, as is the assignment from the value type to a more specific type (integer). However, assignments from the item-or-value value type to a more specific value type (integer) carries a slight performance penalty.For objects, assignments from more general classes (
object or item-or-value) to more specific classes (test-object) carries more of a penalty. Assignments from a specific class (test-object) to the same class are slightly less efficient than specific-to-specific value assignments. Assignments from a specific class (test-object) to a more general class (object) are less efficient, but assignments to item-or-value are not because G2 never has to check if it can assign a class to an item-or-value local variable.Thus, you should always assign local variable value types to the most specific type or the most specific class possible.
The exception to this general rule is casting, described in Effect of Subclassing, Stability, and Casting on Array References.