Rules for overloading methods using widening, boxing, and var-args : Boxing Unboxing « Utility Classes « SCJP






Primitive widening uses the "smallest" method argument possible.

Used individually, boxing and var-args are compatible with overloading.

You CANNOT widen from one wrapper type to another. (IS-A fails.)

You CANNOT widen and then box. (An int can't become a Long.)

You can box and then widen. (An int can become an Object, via Integer.)

You can combine var-args with either widening or boxing.








8.10.Boxing Unboxing
8.10.1.Rules for overloading methods using widening, boxing, and var-args
8.10.2.Boxing, ==, and equals()
8.10.3.Where Boxing Can Be Used
8.10.4.Wrapper reference variables can be null
8.10.5.Overloading Method Matching
8.10.6.Overloading with Boxing and Var-args
8.10.7.Predict the output of the following
8.10.8.boxing beat var-args
8.10.9.Overloading When Combining Widening and Boxing
8.10.10.A boxing operation followed by a widening operation in order to match an invocation to a method.
8.10.11.Overloading in Combination with Var-args
8.10.12.Autoboxing and auto-unboxing are compiler modifications that permit previously illegal combinations of wrappers and primitives.
8.10.13.The wrapper on the left-hand side must correspond exactly to the primitive type on the right-hand side.
8.10.14.The following autoboxing assignment is illegal
8.10.15.Boxing requires an exact match between the wrapper class and the primitive type.
8.10.16.Boxing also occurs when a method's return type is a wrapper.
8.10.17.Unboxing is the automatic extraction of a wrapped value.
8.10.18.Unboxing the parameter