Predict the output of the following : Boxing Unboxing « Utility Classes « SCJP






public class MainClass{
  static void go(int x, int y) { System.out.println("int,int");}
  static void go(byte... x) { System.out.println("byte... "); }
  public static void main(String[] args) {
    byte b = 5;
    go(b,b);         // which go() will be invoked?
  }
}


Overloading with Boxing and Var-args: Widening beats boxing
Overloading with Boxing and Var-args: Widening beats var-args
int,int








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