wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overloading Methods using Widening, Boxing, Var-args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overloading Methods using Widening, Boxing, Var-args" Watch "Overloading Methods using Widening, Boxing, Var-args" New topic

Overloading Methods using Widening, Boxing, Var-args

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 35

Hi all!

Can someone explain each of these for me, example will also be appreciated:

- 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. - I got it, you can't widen Integer to Long, Byte to Integer, etc, because they're objects (unlike primitives) and do not extend each other.
- You CANNOT widen and then box. - I got it. Say there's a byte 5, you can't pass it on Integer, hoping that byte will be widen to int and then will box to Integer, it doesn't work that way.
- You can box and then widen. - I got it. You can convert byte 5 to Byte, and then widen Byte to Object since all classes extends Object. If there's more to it, please let me know.
- You can combine var-args with either widening or boxing. ???

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 724
Primitive widening uses the smallest method argument:

You can combine var-args with widening or boxing:

Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1168
Used individually, boxing and varargs are compatible with overloading can assist.


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
I agree. Here's the link: http://aspose.com/file-tools
subject: Overloading Methods using Widening, Boxing, Var-args
Similar Threads
Exam Lab Test 2 Question
Question on widening ,boxing
Float a=3 doesn't compile but Short a=3 does. Why ?
Long v = 4; why is this faulty?
Question about int... and Integer from Java Inquisition