Boxing and Widening

Sumithra picture Sumithra · Oct 22, 2010 · Viewed 11k times · Source

What is the difference between these two. I know Boxing is converting primitive values to reference. What is widening. Also what should be the sequence first boxing should be done or widening should be done?

Answer

nisha picture nisha · Oct 22, 2010
  1. Widening wins over boxing and var-args
  2. Boxing wins over var-args
  3. Widening of reference variable depends on inheritance(so, Integer cannot be widened to Long. But, Integer widened to Number).
  4. Widen and boxing is not possible
  5. Boxing and widening is possible
  6. var-args can be combined with either boxing or widening