GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Widening and Boxing.... 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 "Widening and Boxing...." Watch "Widening and Boxing...." New topic
Author

Widening and Boxing....

Thangaraj Selvamani
Ranch Hand

Joined: Sep 20, 2008
Posts: 61
Why Java Is not Supporting Widening and Boxing?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3833

Who told you that or where did you get that?


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Pawan Arora
Ranch Hand

Joined: Sep 14, 2008
Posts: 105
He may be using jdk 1.4 or below version in which autoboxing and boxing not exist.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

I think you are trying to say this



SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Anoobkumar Padmanabhan
Ranch Hand

Joined: Aug 08, 2007
Posts: 103
While doing widening and boxing- (for eg: int - long - Long), we are actually doing casting of one class object to another class. ie, int will box into Integer and it is trying to cast to Long class object. since it is not practical, it will give a compilation error.

But you can use this - int to Number- This is because the conversion is int-Integer - Number and Number is the Super class for Integer. So the program below will work fine:



Thanks<br /> <br />Anoobkumar<br />SCJP 1.5
Thangaraj Selvamani
Ranch Hand

Joined: Sep 20, 2008
Posts: 61
Yes Ankit Garg you are correct...



Here The variable "b" First Gets Widening and then Boxing...
so it shows error...this i know very well...
But Why this is (First Gets Widening and then Boxing)not allowed.. to do so in Java ...
[ October 23, 2008: Message edited by: Thangaraj Raj ]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Well Thangaraj we are just kids in front of developers of Java. If java doesn't support anything, then there must be a reason for it. My first post at javaranch was about a problem which I thought was a bug but at last I was proved wrong. When autoboxing was added to java, the developers of java must have thought about thousands of exceptional cases. There must be a specific case which would create problems if Wedening and then boxing was allowed. Let's see if anybody knows such a case. Otherwise it's running as a background thread in my mind. If I will find any such case, I will definitely tell you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Widening and Boxing....