• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Widening and Boxing....

 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why Java Is not Supporting Widening and Boxing?
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who told you that or where did you get that?
 
Pawan Arora
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He may be using jdk 1.4 or below version in which autoboxing and boxing not exist.
 
Ankit Garg
Sheriff
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are trying to say this

 
Anoobkumar Padmanabhan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9528
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic