VOTG
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Programmer Certification (SCJP)
 
RSS feed
 
New topic
Author

widening and boxing...

sweety singh
Ranch Hand

Joined: Dec 15, 2007
Messages: 49

--------------------------------------------------------------------------------
code

class WidenAndBox {
static void go(Long x) { System.out.println("Long"); }

public static void main(String [] args) {
byte b = 5;
go(b); // must widen then box - illegal
}
}

// why cant i widen first and then box... byte can be widened to long and then long can be boxed to Long... then why is it illegal...
Henry Wong
author
Bartender

Joined: Sep 28, 2004
Messages: 9916

// why cant i widen first and then box... byte can be widened to long and then long can be boxed to Long... then why is it illegal...


Simply, because it doesn't. The specification is very specific on what it does.

If you want it to widen and then box, you have to explicitedly widen it first.

Henry

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Professional Certification » Programmer Certification (SCJP)
 
RSS feed
 
New topic
IntelliJ open source

.