This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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: 58

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: 1032
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: 1183
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.
Have you checked out Aspose?
subject: Overloading Methods using Widening, Boxing, Var-args
It's not a secret anymore!